How to put FK constraint on two tables in mysql with one table with InnoDB and other is MyISAM

StackOverflow https://stackoverflow.com/questions/15017660

  •  10-03-2022
  •  | 
  •  

Question

Reason: liquibase.exception.JDBCException:

Error executing SQL ALTER TABLE `User` ADD CONSTRAINT `fk_user_location` FOREIGN KEY (`location_id`) REFERENCES `Location`(`id`) ON DELETE CASCADE:
          Caused By: Error executing SQL ALTER TABLE `UserLocation` ADD CONSTRAINT `fk_user_location_location_id` FOREIGN KEY (`location_id`) REFERENCES `Location`(`id`) ON DELETE CASCADE:
          Caused By: Can't create table 'usiapp_db.#sql-399a_177a7' (errno: 150)
Was it helpful?

Solution

You cannot. You have to convert your MyISAM table to InnoDB if you want create foreign keys to or from it:

ALTER TABLE MyIsamTable ENGINE=InnoDB;

You can do this dynamically, without taking down your database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top