MySQL: Can't create table (errno: 150)

后端 未结 30 2643
误落风尘
误落风尘 2020-11-22 06:48

I am trying to import a .sql file and its failing on creating tables.

Here\'s the query that fails:

CREATE TABLE `data` (
`id` int(10) unsigned NOT NUL         


        
30条回答
  •  孤独总比滥情好
    2020-11-22 07:22

    Sometimes MySQL is just super stupid - i can understand the reason cause of foreign-keys.. but in my case, i have just dropped the whole database, and i still get the error... why? i mean, there is no database anymore... and the sql-user i'm using has no access to any other db's on the server... i mean, the server is "empty" for the current user and i still get this error? Sorry but i guess MySQL is lying to me... but i can deal with it :) Just add these two lines of SQL around your fucky statement:

    SET FOREIGN_KEY_CHECKS = 0;
    # some code that gives you errno: 150
    SET FOREIGN_KEY_CHECKS = 1;
    

    Now the sql should be executed... If you really have a foreign-key problem, it would show up to you by the line where you will enable the checks again - this will fail then.. but my server is just quiet :)

提交回复
热议问题