我使用的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-comments后:我可以获得一个正确的表单来填写评论,但是点击" Post"按钮出现此错误:
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-comments?
编辑:我已修复了我的旧数据库的模型@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-post_comment
函数中的注释得到了正确的模型(ArticlesTable
),但无法找到对象???
答案 0 :(得分:0)
您必须删除managed=False
class Meta:
managed = True
db_table = 'articles_table'
现在makemigrations或syncdb,然后将创建articles_table。