Modify ↓
Ticket #766 (closed defect: fixed)
db.delete_column() not worked for mysql 5.5 when the column is a foreign key
| Reported by: | lgs@… | Owned by: | andrew |
|---|---|---|---|
| Priority: | major | Milestone: | 1.0 |
| Component: | databaseapi | Version: | mercurial |
| Keywords: | Cc: |
Description
The problem is that there is a subtle typo in the mysql.py code that checks if there is a foreign key constraint in that column:
@generic.delete_column_constraints
def delete_column(self, table_name, name):
db_name = self._get_setting('NAME')
# See if there is a foreign key on this column
result = 0
for kind, cname in self.lookup_constraint(db_name, table_name, name):
if kind == 'FOREIGN KEY':
result += 1
fkey_name = cname
if result:
assert result == 1 # We should only have one result, otherwise there's Issues
cursor = self._get_connection().cursor()
drop_query = "ALTER TABLE %s DROP FOREIGN KEY %s"
cursor.execute(drop_query % (self.quote_name(table_name), self.quote_name(fkey_name)))
super(DatabaseOperations, self).delete_column(table_name, name)
The if kind == 'FOREIGN_KEY' should be if kind == 'FOREIGN KEY'
Note the underscore.
Attachments
Change History
Changed 2 years ago by lgs@…
- Attachment foreign_key_check.diff added
comment:1 Changed 2 years ago by lgs@…
Oops, I pasted the fixed version in the ticket description. Sorry for the confusion.
comment:2 Changed 2 years ago by andrew
- Status changed from new to closed
- Resolution set to fixed
- Milestone set to 1.0
Thanks; fixed in [adb5a9cb58cb]
Note: See
TracTickets for help on using
tickets.

Patch for this problem