gpt4 book ai didi

Django loaddata 设置错误

转载 作者:行者123 更新时间:2023-12-01 08:17:58 24 4
gpt4 key购买 nike

尝试在我的本地机器上使用 loaddata 时(win/sqlite):

python django-admin.py loaddata dumpdata.json

我收到以下错误:
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE) ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

如果有帮助,我正在使用 djangoconfig 应用程序:
"""
Django-config settings loader.
"""

import os

CONFIG_IDENTIFIER = os.getenv("CONFIG_IDENTIFIER")
if CONFIG_IDENTIFIER is None:
CONFIG_IDENTIFIER = 'local'

# Import defaults
from config.base import *

# Import overrides
overrides = __import__(
"config." + CONFIG_IDENTIFIER,
globals(),
locals(),
["config"]
)

for attribute in dir(overrides):
if attribute.isupper():
globals()[attribute] = getattr(overrides, attribute)

项目>python manage.py loaddata dumpdata.json --settings=config.base
WARNING: Forced to run environment with LOCAL configuration.

Problem installing fixture 'dumpdata.json': Traceback
(most recent call last):
File "loaddata.py", line 174, in handle
obj.save(using=using)

...


File "C:\Python26\lib\site-packages\django\db\backends\sqlite3\base.py", line
234, in execute
return Database.Cursor.execute(self, query, params)
IntegrityError: columns app_label, model are not unique

最佳答案

请勿使用 django-admin.py除了设置初始项目之外的任何事情。有了项目后,请使用 manage.py相反 - 它设置对您的设置文件的引用。

关于Django loaddata 设置错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5762140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com