gpt4 book ai didi

python manage.py syncdb 不会在 Python Django 中自动加载 initial_data.json fixture

转载 作者:太空狗 更新时间:2023-10-29 14:38:05 26 4
gpt4 key购买 nike

我在 apps/hello 有一个带有应用程序的 Python Django 项目,在 /apps/hello/fixtures/initial_data.json

有一个带有初始数据的 fixture

当我从 github git clone 我的 Python Django 项目时,checkout 需要分支并运行

./manage.py syncdb

它创建没有内容 i 的空表。 e.不从我的 initial_data fixture 加载数据。 Django 要求我注册一个已经在 fixture 中注册的 super 用户。

Operations to perform:
Apply all migrations: admin, contenttypes, hello, auth, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying hello.0001_initial... OK
Applying hello.0002_auto_20141217_1326... OK
Applying hello.0003_auto_20141217_1329... OK
Applying sessions.0001_initial... OK
You have installed Django's auth system, and don't have any superusers defined.
Would you like to create one now? (yes/no): no

但是我可以手动加载钢材数据

./manage.py loaddata apps/hello/fixtures/initial_data.json

Installed 12 object(s) from 1 fixture(s)

如何让 Django 在 syncdb 上自动做同样的事情?

最佳答案

如果您使用的是 Django 1.7 或更高版本,您可能应该知道 automatic loading of fixtures has been deprecated :

If an application uses migrations, there is no automatic loading of fixtures. Since migrations will be required for applications in Django 2.0, this behavior is considered deprecated. If you want to load initial data for an app, consider doing it in a data migration.

如果您使用的是新的内置迁移,则无法自动加载固定装置。

关于python manage.py syncdb 不会在 Python Django 中自动加载 initial_data.json fixture,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27548075/

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