Error 1215 Cannot add foreign key constraint

后端 未结 2 1819
情深已故
情深已故 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:55

    I had the same kind of issue and I fixed it by making sure that collation and types matched in both FK and the parent PK.

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题