[Django]-South – migrating django application from sqlite to mysql

5👍

First, you can’t pick and choose migrations to run. migrate core 0040 means run all migrations up to 0040. In other words, it wouldn’t run 0041, but it would run 0001-0040.

Now, it’s side-stepping your question a bit, but if you have not moved this project to production yet, you don’t actually need all those migrations. Assuming they’re all schemamigrations you can rollback to zero with:

python manage.py migrate core zero

Then, delete them all (including 0001_initial.py) and simply run again:

python manage.py schemamigration --initial core

To regenerate the initial migration. It will base it off the current state of your models, negating the need for 40 migrations.

It’s always a good idea to compress your migrations like this before you move new code to production. Since this is the first launch, you can remove them all and start from scratch, but in future iterations, if you generate 5 migrations during the course of development, before you commit, rollback to before the first of those, then delete those 5 and then generate a new schemamigration. The result is just one migration with all the changes of those 5. Then, you can commit that and migrate in production.

It may not solve your problem completely here, but it will definitely make things simpler to debug.

2👍

Very occasionally, I’ve seen problems with migrations when deploying a project on a mysql backend.

Since you are deploying a fresh copy, you do have a couple options for sidestepping the need to run all of your mightations:

First, if you want to maintain your migration history as-is, you can force syncdb to create all of your tables regardless of migrations, and then run fake migrations to get your new database up to date. That would look like:

python manage.py syncdb --all
python manage.py migrate --fake

Alternatively, if you don’t care about your historical migrations, you can clear the old migrations out (just delete them) and then create a new initial migration, like:

python manage.py schemamigration --initial core

Just be sure that you also clear out the south_migrationhistory table in your dev database so that everything stays in sync between dev and prod

Leave a comment