2015-11-01 86 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

相關問題