0

my で定義されたレガシーデータベースを(「通常の」データベースに加えて)使用しています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 コメントによって提供されます):

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) を取得しますが、オブジェクトが見つかりませんか???

4

1 に答える 1

0

削除する必要がありますmanaged=False

class Meta:
    managed = True
    db_table = 'articles_table'

makemigrations または syncdb を実行すると、articles_table が作成されます。

于 2015-11-01T19:46:51.147 に答える