[Django]-Django South Migration does not work the first time around

3👍

Turns out this is a bug in South.

http://south.aeracode.org/ticket/1281

👤Mark

1👍

Of course its going to be like this, you have not made any intial schemamigrations. The right way would be like this:

  1. Register your django apps with south first. So something like:
    python manage.py schemamigration --initial <app_name>.
  2. Then you run manage.py syncdb.
  3. After this, you run migrate like so python manage.py migrate <apps>, please note that simply running migrate will just migrate all your registered apps. I tend to do this.
  4. If you change models to change the schema, then you can simply use:
    manage.py schemamigration --auto

The problem that you are alluding to is this. Once you run syncdb, you already get a table crated, south had nothing to do with this. What you are hence doing is querying a database that has no migration control (iirc).

1👍

It’s a bad practice to issue python manage.py syncdb; python manage.py migrate --all for the first time. First of all, I won’t trust much in --all option. It may include Django’s oficial libraries and you certainly don’t want that, even when There’s nothing to migrate in them. I rather go by python manage.py migrate <app_name1> <app_name2> ...

But for what South concerns, the way of using South is:

  1. Create an app
  2. Create a migration for it with python manage.py schemamigration --initial <app>
  3. Convert to south and exising migration with python manage.py convert_to_south <app> --auto
  4. Do some modifications to the app and then python manage.py migrate <app>

Your approach might actually work, but take into account that when you do migrate --all you don’t controll the order of migrations applied, and python manage.py syncdb won’t assure the contentType your accessing is (myapp, mymodel) available at that time.

The error is appearing only first time because maybe the migration is actually being applied once. And getting save in the south_migrationhistory table as already applied, so when you issue the command again, it ignores it.

My advice, migrate first the target apps, after the syncdb command. If this doesn’t work or things get messy, try this:

  1. Comment the line 'south', in INSTALLED_APPS
  2. Issue python manage.py syncdb
  3. Remove comment from line #'south', in INSTALLED_APPS
  4. Issue the final command python manage.py migrate --all

Good luck, hope this helps!

Leave a comment