Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#1373 closed defect (fixed)

[patch] magic-removal: MySQL does not support DROP CONSTRAINT

Reported by: Jan Rademaker <j.rademaker@…> Owned by: Adrian Holovaty
Component: Core (Management commands) Version: magic-removal
Severity: major Keywords: mysql constraint foreign
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Although MySQL 4 & 5 support ADD CONSTRAINT they don't support DROP CONSTRAINT. This causes manage sqlreset [app] and manage sqlclear [app] to produce invalid sql statements.

MySQL MaxDB, however, _does_ support DROP CONSTRAINT.

See #1082 also.

Attachments (2)

fix_drop_foreignkey.diff (2.8 KB ) - added by Geert Vanderkelen <geert@…> 19 years ago.
newfix_drop_foreignkey.diff (2.7 KB ) - added by njharman@… 19 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by pb@…, 19 years ago

I'm not attaching this as a patch file because it's a hack, not a fix, but if you just need to get sqlreset and sqlclear working with &!@$# MySQL today, then:

Index: django/db/backends/mysql/base.py
===================================================================
--- django/db/backends/mysql/base.py    (revision 2545)
+++ django/db/backends/mysql/base.py    (working copy)
@@ -86,7 +86,7 @@
             self.connection.close()
             self.connection = None
 
-supports_constraints = True
+supports_constraints = False
 
 def quote_name(name):
     if name.startswith("`") and name.endswith("`"):

A slightly more granular fix would be to break down this attribute into supports_constraint_add and supports_constraint_drop, then make the appropriate updates in the backend files. The differences between MySQL MaxDB will still need to be addressed, though.

comment:2 by Russell Cloran <russell@…>, 19 years ago

I'm having a similar problem. (At the moment worked around by ./manage.py sqlreset app | sed 's/DROP CONSTRAINT/DROP FOREIGN KEY/' | mysql). I have no idea how to fix it, just thought some confirmation would be good :)

comment:3 by Geert Vanderkelen <geert@…>, 19 years ago

Keywords: mysql constraint foreign added
Severity: normalmajor
Summary: magic-removal: MySQL does not support DROP CONSTRAINT[patch] magic-removal: MySQL does not support DROP CONSTRAINT

I'm attaching a patch which fixes this problem. It will use the 'get_foreignkey_drop' function from the backend module so different syntax is supported. In MySQL this is ALTER TABLE <table> DROP FOREIGN KEY <name>;.

I took the liberty to also add these functions to the other backends, but I couldn't test those. Although I think it should work fine, might be good to test them ;)

I put severity to major, since this basicly makes the sqlreset for example, not work for MySQL.

by Geert Vanderkelen <geert@…>, 19 years ago

Attachment: fix_drop_foreignkey.diff added

by njharman@…, 19 years ago

Attachment: newfix_drop_foreignkey.diff added

comment:4 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: newclosed

(In [2732]) magic-removal: Fixed #1373 -- Factored out database-specific 'DROP CONSTRAINT' syntax, to get sqlreset/sqlclear working with MySQL. Thanks, njharman

Note: See TracTickets for help on using tickets.
Back to Top