djangconstance:关系“constance_config”不存在

2024-04-28 15:05:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我在使用^{}时遇到问题。在

我遵循以下步骤:https://django-constance.readthedocs.io/en/latest/index.html

  1. pip install "django-constance[database]"
  2. 'constance'和{}添加到INSTALLED_APPS
  3. 将以下内容放在设置文件的底部(它不是被调用的setings.py而是common.py):

    CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend'
    CONSTANCE_DATABASE_PREFIX = 'constance:my_app_name:'
    CONSTANCE_CONFIG = {
        'THE_ANSWER': (42,
                       'Answer to the Ultimate Question of Life, The Universe, and Everything'),
    }
    
  4. 然后运行python manage.py migrate database

但是没有创建动态设置表。当我试图列出constance设置时,会发生这种情况:

^{pr2}$


我运行的是python3.5.2、Django 1.11.3和Django constance 2.0.0。在

有什么线索吗?在


Tags: pipdjangopyhttpsioconstanceindexhtml
2条回答

我不太清楚原因,但以下是有效的方法:

  1. 存在database初始迁移

    $ python manage.py showmigrations database
    database
    [X] 0001_initial
    

    但桌子本身不是

    \dt *constance*
    No matching relations found.
    
  2. 所以我删除了django_migrations的迁移

    delete from django_migrations where app = 'database';
    
  3. 重新运行迁移

    python manage.py migrate database
    

就这样。constance list行为:

$ python manage.py constance list
THE_ANSWER  42

如果要使用数据库后端更改,请检查项目设置文件上的INSTALLED_APPS,请类似于以下内容:

INSTALLED_APPS = (
    # other apps
    'constance.backends.database',
)

Read more

相关问题 更多 >