Ticket #766 (closed defect: fixed)

Opened 5 years ago

Last modified 5 years ago

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:


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:

    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.


foreign_key_check.diff (494 bytes) - added by lgs@… 5 years ago.
Patch for this problem

Change History

Changed 5 years ago by lgs@…

Patch for this problem

comment:1 Changed 5 years ago by lgs@…

Oops, I pasted the fixed version in the ticket description. Sorry for the confusion.

comment:2 Changed 5 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.