Can't create table (errno: 150) on FOREIGN KEY

前端 未结 2 1258
[愿得一人]
[愿得一人] 2021-01-28 00:53

I saw a lot of same question but I couldn\'t solve my case.

If I run this code:



        
2条回答
  •  轮回少年
    2021-01-28 00:53

    Tags.id_articls is a signed integer while Articl.id is an unsigned integer. MySQL requires referencing field to be exactly the same type. Make Tags.id_articls unsigned to have it work.

    Additionally, the table names in the column lists are not allowed in MySQL. It is always clear which table is meant: first the referencing table and then the referenced table. So change

    FOREIGN KEY(Tags.id_articls) REFERENCES Articls(Articls.id)
    

    into

    FOREIGN KEY(id_articls) REFERENCES Articls(id)
    

    and it will work.

提交回复
热议问题