#1373 closed defect (fixed)
[patch] magic-removal: MySQL does not support DROP CONSTRAINT
| Reported by: | 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)
Change History (6)
comment:1 by , 20 years ago
comment:2 by , 20 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 , 20 years ago
| Keywords: | mysql constraint foreign added |
|---|---|
| Severity: | normal → major |
| 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 , 20 years ago
| Attachment: | fix_drop_foreignkey.diff added |
|---|
by , 20 years ago
| Attachment: | newfix_drop_foreignkey.diff added |
|---|
comment:4 by , 20 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
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.