Error 1215 Cannot add foreign key constraint

后端 未结 2 1818
情深已故
情深已故 2021-01-24 11:32

Table CARGO

DROP TABLE IF EXISTS \"hibernatecurso\".\"cargo\";
CREATE TABLE  \"hibernatecurso\".\"cargo\" (
  \"idcargo\" int(11) NOT NULL DEFAULT \'0\',
  \"fun         


        
2条回答
  •  执念已碎
    2021-01-24 11:57

    I maybe have hard time reading, but I don't see any index on cargo.funcao. This is very probably missing:

    ALTER TABLE `hibernatecurso`.`cargo` ADD INDEX `idx_funcao`(`funcao`);
    

    InnoDB permits a foreign key to reference any index column or group of columns. However, in the referenced table, there must be an index where the referenced columns are listed as the first columns in the same order.

    http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html

提交回复
热议问题