2015-11-01 75 views
0

我使用的是legacy database(除了 '正常' 数据库),在我settings.py定义:Django评论和遗留数据库? “OperationalError:没有这样的表”

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已经安装Django的意见之后1.8.5:我可以得到一个正确的表格填写评论,但点击“发布”按钮,得到这个错误:

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的意见并没有发现我的数据库里面我的表?实际上使用Django注释可以使用遗留数据库吗?

编辑:我已经解决了型号为我的遗产数据库@Geo雅各布建议:

class Meta: 
    managed = True 
    db_table = 'articles_table' 

但现在我得到了一个错误页面(通过Django的给予,而不是一个调试页) :在post_comment功能

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的意见得到正确的模型(ArticlesTable),但无法找到对象???

回答

0

您必须删除managed=False

class Meta: 
    managed = True 
    db_table = 'articles_table' 

现在makemigrations或执行syncdb,那么articles_table将被创建。

+0

现在我得到了: 评论帖子不允许(400) 为什么:\t没有匹配内容类型'articles.articlestable'和对象PK'1'的对象。 您尝试发布到此视图的评论未保存,因为某些内容会篡改评论表单中的安全信息。 – ThePhi

相关问题