I have a bootstrap script that performs syncdb and migrate:
import settings
from django.core.management import setup_environ, call_command
setup_environ(settings) # Setting up the env settings
call_command('syncdb', migrate=True, interactive=False) # Sync the database
Pre-Requisites:
django-southfor migrations.
Process happening:
initial_datafixture contains data for a model that is created by migrations.syncdbis executed it creates all the tables except for those apps where migrations exists.- Post
syncdbit tries to loadinitial_dataand raises error of db not found because the table for app with migrations were not created by syncdb. [ Problem ] - Then it performs migration which creates the db.
- Post
migrationit automatically loadsinitial_datasuccessfully this time.
Problem:
- How can I get rid of the
error, when it tries to load fixture for the table that is not yet created ? - Can I edit the above script in a way so that it loads
initial_dataonly after performing themigration?
You could disable loading initial data when syncdb:
From the source code of syncdb.py: