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

前端 未结 2 1231
[愿得一人]
[愿得一人] 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.

    0 讨论(0)
  • 2021-01-28 00:55

    You need to declare both Articls.id and Tags.id_articls signed or unsigned

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