Ticket #697 (assigned defect)

Opened 5 years ago

Last modified 4 years ago

MySQL rename column and table fails when present in a foreign key

Reported by: s_dalton@… Owned by: andrew
Priority: minor Milestone: 1.0
Component: databaseapi Version: 0.7
Keywords: mysql foreign key fk rename renaming Cc:


MySQL (or south) fails to manage foreign key mappings when renaming either columns or tables.

I found this occuring on south 0.7, against the following mysql
mysql Ver 14.12 Distrib 5.0.51b, for Win32 (ia32)

I will attach a (debug/working) fix for this (I'll provide a proper diff with better code at a later point)


mysql.py (9.8 KB) - added by s_dalton@… 5 years ago.
Full 0.7 mysql.py file
generic.py (32.4 KB) - added by s_dalton@… 5 years ago.
Full generic.py file to show fix
south-0.7-697.diff (4.0 KB) - added by s_dalton@… 4 years ago.
Patch to fix the issue

Change History

Changed 5 years ago by s_dalton@…

Full 0.7 mysql.py file

Changed 5 years ago by s_dalton@…

Full generic.py file to show fix

comment:1 Changed 5 years ago by Llew <ortsed@…>

If you change line 29 in mysql.py to:

has_ddl_transactions = True

then it should work. I think that statement was set up for an older version of MYSQL that did not allow DDL Transactions.

comment:2 Changed 5 years ago by andrew

That comment is entirely unrelated; not only is this not a problem with transactions, MySQL still doesn't have DDL transactions, as I pointed out on the mailing list.

comment:3 Changed 5 years ago by andrew

  • Status changed from new to assigned

Also, to the original author: This ticket is probably a duplicate of #679 - could you take a look there and see? In addition, whole files are basically useless to me, since I don't know what version of the code to compare them against - I'll need to wait for diffs to give an opinion.

comment:4 Changed 4 years ago by s_dalton@…

I dont think its related enough to merge the issues; #697 (this) is about renaming columns or tables. #679 (other issue) I think is about the changing of datatypes. The operations are done in separate methods.
#697 may be able to be fixed in a similar way to my fix here (if accepted of course)

Changed 4 years ago by s_dalton@…

Patch to fix the issue

comment:5 Changed 4 years ago by andrew

Alright, sorry for the really, really slow response here.

Firstly, the patch doesn't apply cleanly, but that's probably me waiting five weeks, so no matter.

Secondly, the change to south/db/mysql.py has a call on lines 83 and 133 to self.foreign_key_sql that doesn't do anything with the returned SQL (presumably, it should be executed?)

comment:6 Changed 4 years ago by aarranz@…


I've updated the patch s_dalton provided and tested it. You can find the new version in the mysql-fixes branch at https://bitbucket.org/aarranz/south-aarranz.

In the other hand, I've found other problems not directly related to this ticket that I've also "fixed" but I'm not sure they are in shape to be included in south. Please review my commits and if they make sense I can create new tickets for them and/or repair them.

comment:7 Changed 4 years ago by beyondwords

I didn't see aarranz changes until I had started my own solution https://bitbucket.org/beyondwords/south-mysql
I believe this makes fewer database calls and follows the existing structure a bit more closely, but I am open to comments.

Note: See TracTickets for help on using tickets.