MySQL “ERROR 1005 (HY000): Can't create table 'foo.#sql-12c_4' (errno: 150)”

后端 未结 14 793
情深已故
情深已故 2020-12-03 04:13

I was working on creating some tables in database foo, but every time I end up with errno 150 regarding the foreign key. Firstly, here\'s my code for creating t

14条回答
  •  既然无缘
    2020-12-03 05:04

    I use Ubuntu linux, and in my case the error was caused by incorrect statement syntax (which I found out by typing perror 150 at the terminal, which gives

    MySQL error code 150: Foreign key constraint is incorrectly formed

    Changing the syntax of the query from

    alter table scale add constraint foreign key (year_id) references year.id;
    

    to

    alter table scale add constraint foreign key (year_id) references year(id);
    

    fixed it.

提交回复
热议问题