Ticket #1063 (closed enhancement: worksforme)

Opened 3 years ago

Last modified 3 years ago

More meaningful error messages about database errors during the migration

Reported by: lumi77 Owned by: andrew
Priority: major Milestone: 1.0
Component: commands Version: 0.7.3
Keywords: Cc:

Description

To mention a concrete example, a database migration was failing on

db.delete_unique('guardian_userobjectpermission', ['user_id', 'object_id', 'content_type_id', 'permission_id'])

The constraint was actually present in the database. So I'm not sure why MySQL decided that it does not exist. The easy way to complete the migration would be to inspect which step failed, delete the constraint manually in the database, comment out the line above and rerun the migration.

It would be nice if South displayed an error message about what went wrong. At the moment, I get a stack trace from further processing where South tries to rollback the migration step.

My simple approach to find out what the database error was - print the exception in run_migration

    def run_migration(self, migration):
        migration_function = self.direction(migration)
        south.db.db.start_transaction()
        try:
            migration_function()
            south.db.db.execute_deferred_sql()
        except Exception, e:
            print e
            south.db.db.rollback_transaction()
            if not south.db.db.has_ddl_transactions:
                print self.run_migration_error(migration)
            raise
        else:
            south.db.db.commit_transaction()

Anyway, I am impressed by this tool.

Change History

comment:1 Changed 3 years ago by andrew

  • Status changed from new to closed
  • Resolution set to worksforme
  • Milestone set to 1.0

South _does_ print the error that caused a migration - it usually appears above the error message that moans about you using MySQL. If you look in the function, you'll see there's a "raise" at the end of the exception handler to re-propagate the exception that occurs.

Note: See TracTickets for help on using tickets.