Django

Code

Ticket #1373 (closed: fixed)

Opened 3 years ago

Last modified 2 years ago

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

Reported by: Jan Rademaker <j.rademaker@gmail.com> Assigned to: adrian
Milestone: Component: django-admin.py
Version: magic-removal Keywords: mysql constraint foreign
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

fix_drop_foreignkey.diff (2.8 kB) - added by Geert Vanderkelen <geert@kemuri.org> on 03/25/06 11:05:19.
newfix_drop_foreignkey.diff (2.7 kB) - added by njharman@knoggin.com on 04/21/06 08:35:32.

Change History

03/21/06 18:28:29 changed by pb@e-scribe.com

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.

03/22/06 06:30:35 changed by Russell Cloran <russell@hbd.com>

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 :)

03/25/06 11:04:35 changed by Geert Vanderkelen <geert@kemuri.org>

  • keywords set to mysql constraint foreign.
  • severity changed from normal to major.
  • summary changed from magic-removal: MySQL does not support DROP CONSTRAINT to [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.

03/25/06 11:05:19 changed by Geert Vanderkelen <geert@kemuri.org>

  • attachment fix_drop_foreignkey.diff added.

04/21/06 08:35:32 changed by njharman@knoggin.com

  • attachment newfix_drop_foreignkey.diff added.

04/23/06 16:45:38 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #1373 ([patch] magic-removal: MySQL does not support DROP CONSTRAINT)




Change Properties
Action