我有一个Python Django项目,其应用程序位于apps/hello
和一个带有初始数据的灯具,位于/apps/hello/fixtures/initial_data.json
当我git clone
从github获得Python Django项目时,checkout
需要分支并运行
./manage.py syncdb
它会创建没有内容的空表,即不会从我的initial_data
灯具中加载数据。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'),
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句