我正在使用一个遗留数据库(除了一个“普通”数据库),定义在我的settings.py
:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'articles_database': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'articles.db'),
} }
在我models.py
的与:
from django.db import models
class ArticlesTable(models.Model):
id = models.IntegerField(primary_key=True) # AutoField?
article_type = models.TextField(blank=True, null=True) # This field type is a guess.
article_name = models.TextField(blank=True, null=True) # This field type is a guess.
article_number = models.IntegerField(db_column='article_number', blank=True, null=True) # Field name made lowercase.
class Meta:
managed = False
db_table = 'articles_table'
在我的 Django 1.8.5 上安装 Django-comments 后:我可以获得一个正确的表单来填写评论,但是单击“发布”按钮会出现此错误:
OperationalError at /comments/post/
no such table: articles_table
突出显示错误行:
/home/gus/.Envs/python3_django/lib/python3.4/site-packages/django_comments/views/comments.py in post_comment
56. target = model._default_manager.using(using).get(pk=object_pk)
显然,Django-comments 没有在我的数据库中找到我的表?实际上是否可以将遗留数据库与 Django 评论一起使用?
编辑: 我已经按照@Geo Jacob 的建议为我的旧数据库修复了模型:
class Meta:
managed = True
db_table = 'articles_table'
但是现在我得到了一个错误页面(由 Django-comments 提供,而不是 Debug 页面):
Comment post not allowed (400)
Why: No object matching content-type 'articles.articlestable' and
object PK '1' exists.
The comment you tried to post to this view wasn't saved because
something tampered with the security information in the comment
form. The message above should explain the problem, or you can check
the comment documentation for more help.
函数中的 Django-commentspost_comment
得到正确的模型(ArticlesTable
)但找不到对象???