Ahsan
Ahsan

Reputation: 11832

how to change the order of south migrations

I have around fifty migrations in my store app, some of them are schemamigration and some datamigration. Now i want to run 0039_add_column_is_worldwide before 0037_some_values_to_objects. So I changed there name 0037_add_column_is_worldwide and 0039_some_values_to_objects.

It works fine when i did syncdb for new db but while migrating for a new migration in existing db it gives this error.

raise exceptions.InconsistentMigrationHistory(problems) south.exceptions.InconsistentMigrationHistory: Inconsistent migration history The following options are available: --merge: will just attempt the migration ignoring any potential dependency conflicts.

I didn't want to lose my data, so is there anyway to change the order of these migrations?

Upvotes: 2

Views: 2416

Answers (2)

Bite code
Bite code

Reputation: 596743

Migration are stored in DB when ran, so if you already applied these migrations south is going to get lost. Your alternatives:

  • flush the migration table (will cause all migration to run again if you call migrate)
  • rollback these migrations (before renaming)
  • fake these migrations (migrate --fake, but the numbers may conflict with the one in DB anyway)

Rollback seems the safest to me, just be sure everybody in your project do the same.

If you are still in dev and you have no prod database, you can always restart from zero:

  • flush the south db
  • migrate --fake

Upvotes: 4

guettli
guettli

Reputation: 27826

I guess your database has already done "0037_some_values_to_objects".

I would do it like this:

Remove the code inside the forward() and other method in "0037_some_values_to_objects". This migration does nothing. Now add two new migrations.

Rule of thumb: If one system has done a migration, don't delete it. Make it empty.

Upvotes: 0

Related Questions