【发布时间】:2015-11-01 19:36:31
【问题描述】:
我正在使用legacy database(除了“普通”数据库),在我的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-cmets 后:我可以得到一个正确的表格来填写评论,但是单击“发布”按钮会出现此错误:
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-cmets 没有在我的数据库中找到我的表?实际上是否可以在 Django-cmets 中使用旧数据库?
编辑:我已经按照@Geo Jacob 的建议修复了旧数据库的模型:
class Meta:
managed = True
db_table = 'articles_table'
但是现在我得到了一个错误页面(由 Django-cmets 提供,不是 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.
post_comment 函数中的 Django-cmets 获得了正确的模型 (ArticlesTable) 但找不到对象???
【问题讨论】:
标签: django django-comments legacy-database