MySQL error cannot add foreign key constraint

后端 未结 6 1643
既然无缘
既然无缘 2021-01-14 01:52

what is wrong?

mysql> create table price(
    -> p_code char(1) not null,
    -> p_description varchar(20),
    -> p_rentfee decimal(2,2) not nul         


        
6条回答
  •  暖寄归人
    2021-01-14 02:31

    • Engine should be the same e.g. InnoDB
    • Datatype should be the same, and with same length. e.g. VARCHAR(20)
    • Collation Columns charset should be the same. e.g. utf8
      Watchout: Even if your tables have same Collation, columns still could have different one.
    • Unique - Foreign key should refer to field that is unique (usually primary key) in the referenced table.

提交回复
热议问题