Reputation: 1664
I have Python Django project with app at apps/hello
and a fixture with initial data at /apps/hello/fixtures/initial_data.json
When I git clone
my Python Django project from github, checkout
needed branch and run
./manage.py syncdb
it creates empty tables with no content i. e. does not load data from my initial_data
fixture. Django asks me to register a superuser which is already registered in 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
However I can steel load data manually
./manage.py loaddata apps/hello/fixtures/initial_data.json
Installed 12 object(s) from 1 fixture(s)
How to make Django do the same thing automatically on syncdb?
Upvotes: 3
Views: 687
Reputation: 864
I had the same problem, and I solved it by adding a few lines in my settings.py
FIXTURE_DIRS = (
os.path.join(BASE_DIR, 'hello/fixtures'),
)
Upvotes: 1
Reputation: 137075
If you are using Django version 1.7 or later, you should probably know that 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.
If you're using the new built-in migrations, automatic loading of fixtures won't work.
Upvotes: 3