0

By mistake I added two foreign keys referring to the same table and column. The SHOW CREATE TABLE table_a look like:

table_a | CREATE TABLE `table_a` (
`id` char(36) NOT NULL,
`fk` int(11) default NULL,
`created_at` datetime default NULL,
PRIMARY KEY  (`id`),
KEY `fk` (`fk`),
CONSTRAINT `table_a_ibfk_1` FOREIGN KEY (`fk`) REFERENCES `table_b` (`id`),
CONSTRAINT `table_a_fkey` FOREIGN KEY (`fk`) REFERENCES `table_b` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8

My only solution at this point is to iterate over all the keys/constraints on the column and remove them followed by adding the cascade key one more time.

Is there a way to remove only the non-cascade constraint using SQLAlchemy Migrate?

Carl
  • 740
  • 8
  • 18

1 Answers1

0

Did you try?

cons = ForeignKeyConstraint(columns=[table.c.fk],
                            refolumns=[table_b.c.id],
                            name="table_a_ibfk_1")
cons.drop(engine=migrate_engine)
Boris Pavlovic
  • 1,279
  • 8
  • 17