django - south :Getting error with migration

40 views
Skip to first unread message

Ram Ganesh

unread,
Aug 21, 2014, 9:56:12 AM8/21/14
to south...@googlegroups.com
Hi all

I got this error while migrating app in django. I am using mysql
FATAL ERROR - The following SQL query failed: ALTER TABLE `my_table` ADD CONSTRAINT `my_table_my_field_18bc0d26_uniq` UNIQUE (`my_field`)
The error was: (1062, "Duplicate entry '123' for key 'my_table_my_field_18bc0d26_uniq'")
 ! Error found during real run of migration! Aborting.

 ! Since you have a database that does not support running
 ! schema-altering statements in transactions, we have had
 ! to leave it in an interim state between migrations.

! You *might* be able to recover with:   - no dry run output for delete_unique_column() due to dynamic DDL, sorry

 ! The South developers regret this has happened, and would
 ! like to gently persuade you to consider a slightly
 ! easier-to-deal-with DBMS (one that supports DDL transactions)
 ! NOTE: The error which caused the migration to fail is further up.

Mysql support south or not?

what should i do?

Thanks,

Ram Ganesh K

Shai Berger

unread,
Aug 21, 2014, 4:33:38 PM8/21/14
to south...@googlegroups.com
Hi,
South supports MySql, but MySql has limitations that South cannot fix. One of
them -- which you have run into -- is (essentially) that if a migration runs
into an error, there is no good way to cancel the whole migration
automatically.

If your migration had made some changes to the database before the error, you
would need to fix the database yourself, without South's help. However, it
seems like all the migration tried to do was add a unique constraint to a
single column. If that is the case, then you don't have to worry about the
scary message. The migration didn't manage to do anything anyway.

That said, if you have a choice about this, I recommend working with
PostgreSQL rather than MySql, exactly for the reason specified in the message;
with PostgreSQL, if an error is encountered, the whole migration can just be
rolled back. Then, you are in a much better position to fix things.

> what should i do?
>

First of all -- don't panic.

The error reported was:
> FATAL ERROR - The following SQL query failed: ALTER TABLE `my_table` ADD
> CONSTRAINT `my_table_my_field_18bc0d26_uniq` UNIQUE (`my_field`)

and in more detail:

> The error was: (1062, "Duplicate entry '123' for key
> 'my_table_my_field_18bc0d26_uniq'")

So, you tried to make "my_field" unique, while the database had more than one
record with my_field='123'. You need to clean up your data before you can add
the constraint.

HTH,
Shai.
Reply all
Reply to author
Forward
0 new messages