Commits

andymccurdy  committed 9653402

Added --ignore-ghost-migrations option to the migrate command. This is a fix for #411.

  • Participants
  • Parent commits a162189

Comments (0)

Files changed (2)

File south/management/commands/migrate.py

             help="Doesn't execute the SQL generated by the db methods, and doesn't store a record that the migration(s) occurred. Useful to test migrations before applying them."),
         make_option('--delete-ghost-migrations', action='store_true', dest='delete_ghosts', default=False,
             help="Tells South to delete any 'ghost' migrations (ones in the database but not on disk)."),
+        make_option('--ignore-ghost-migrations', action='store_true', dest='ignore_ghosts', default=False,
+            help="Tells South to ignore any 'ghost' migrations (ones in the database but not on disk) and continue to apply new migrations."),
         make_option('--database', action='store', dest='database',
             default=DEFAULT_DB_ALIAS, help='Nominates a database to synchronize. '
                 'Defaults to the "default" database.'),
     help = "Runs migrations for all apps."
     args = "[appname] [migrationname|zero] [--all] [--list] [--skip] [--merge] [--no-initial-data] [--fake] [--db-dry-run] [--database=dbalias]"
 
-    def handle(self, app=None, target=None, skip=False, merge=False, backwards=False, fake=False, db_dry_run=False, show_list=False, database=DEFAULT_DB_ALIAS, delete_ghosts=False, **options):
+    def handle(self, app=None, target=None, skip=False, merge=False, backwards=False, fake=False, db_dry_run=False, show_list=False, database=DEFAULT_DB_ALIAS, delete_ghosts=False, ignore_ghosts=False, **options):
 
         # Work out what the resolve mode is
         resolve_mode = merge and "merge" or (skip and "skip" or None)
                     skip = skip,
                     database = database,
                     delete_ghosts = delete_ghosts,
+                    ignore_ghosts = ignore_ghosts,
                 )
                 if result is False:
                     sys.exit(1) # Migration failed, so the command fails.

File south/migration/__init__.py

                 to_check.extend(checking.dependencies)
     return result
 
-def check_migration_histories(histories, delete_ghosts=False):
+def check_migration_histories(histories, delete_ghosts=False, ignore_ghosts=False):
     "Checks that there's no 'ghost' migrations in the database."
     exists = SortedSet()
     ghosts = []
         if delete_ghosts:
             for h in ghosts:
                 h.delete()
-        else:
+        elif not ignore_ghosts:
             raise exceptions.GhostMigrations(ghosts)
     return exists
 
         direction = LoadInitialDataMigrator(migrator=direction)
     return direction
 
-def migrate_app(migrations, target_name=None, merge=False, fake=False, db_dry_run=False, yes=False, verbosity=0, load_initial_data=False, skip=False, database=DEFAULT_DB_ALIAS, delete_ghosts=False):
+def migrate_app(migrations, target_name=None, merge=False, fake=False, db_dry_run=False, yes=False, verbosity=0, load_initial_data=False, skip=False, database=DEFAULT_DB_ALIAS, delete_ghosts=False, ignore_ghosts=False):
     app_label = migrations.app_label()
 
     verbosity = int(verbosity)
         Migrations.invalidate_all_modules()
     
     south.db.db.debug = (verbosity > 1)
-    applied = check_migration_histories(applied, delete_ghosts)
+    applied = check_migration_histories(applied, delete_ghosts, ignore_ghosts)
     
     # Guess the target_name
     target = migrations.guess_migration(target_name)