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
  •  | 
  •  

Domanda

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)
È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top