python manage.py syncdb不会在python Django中自动加载初始_data.json fixture
我有一个Python Django项目,其中app位于python manage.py syncdb不会在python Django中自动加载初始_data.json fixture,python,django,git,fixtures,django-syncdb,Python,Django,Git,Fixtures,Django Syncdb,我有一个Python Django项目,其中app位于apps/hello,fixture的初始数据位于/apps/hello/fixtures/initial_data.json 当我从github中克隆我的Python Django项目时,checkout需要分支并运行 ./manage.py syncdb 它创建没有内容i的空表。E不从我的初始数据夹具加载数据。Django要求我注册一个已经在fixture中注册的超级用户 Operations to perform: Apply a
apps/hello
,fixture的初始数据位于/apps/hello/fixtures/initial_data.json
当我从github中克隆我的Python Django项目时,checkout
需要分支并运行
./manage.py syncdb
它创建没有内容i的空表。E不从我的初始数据夹具加载数据。Django要求我注册一个已经在fixture中注册的超级用户
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上自动执行相同的操作?我也遇到了同样的问题,我通过在我的settings.py中添加几行代码解决了这个问题
FIXTURE_DIRS = (
os.path.join(BASE_DIR, 'hello/fixtures'),
)
如果您使用的是Django 1.7版或更高版本,您可能应该知道:
如果应用程序使用迁移,则不会自动加载装置。由于Django 2.0中的应用程序需要迁移,因此这种行为被认为是不推荐的。如果您想为应用程序加载初始数据,请考虑在数据迁移中执行它。
如果您正在使用新的内置迁移,那么自动加载装置将不起作用