MySQL Error 1215: Cannot add foreign key constraint

前端 未结 30 2821
予麋鹿
予麋鹿 2020-11-22 01:37

I am trying to forward engineer my new schema onto my db server, but I can\'t figure out why I am getting this error. I\'ve tried to search for the answer here, but everyth

30条回答
  •  花落未央
    2020-11-22 02:03

    For MySQL (INNODB) ... get definitions for columns you want to link

    SELECT * FROM information_schema.columns WHERE 
    TABLE_NAME IN (tb_name','referenced_table_name') AND 
    COLUMN_NAME  IN ('col_name','referenced_col_name')\G
    

    compare and verify both column definitions have

    same COLUMN_TYPE(length), same COLATION

    could be helpfull to play like

    set foreign_key_checks=0;
    ALTER TABLE tb_name ADD FOREIGN KEY(col_name) REFERENCES ref_table(ref_column) ON DELETE ...
    set foreign_key_checks=1;
    

提交回复
热议问题