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

后端 未结 30 2636
误落风尘
误落风尘 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:14

    Make sure that the all tables can support foreign key - InnoDB engine

    0 讨论(0)
  • 2020-11-22 07:15

    I had a similar problem when dumping a Django mysql database with a single table. I was able to fix the problem by dumping the database to a text file, moving the table in question to the end of the file using emacs and importing the modified sql dump file into the new instance.

    HTH Uwe

    0 讨论(0)
  • 2020-11-22 07:16

    In my case. I had problems with engine and charset because my Hosting server change settings and my new tables was MyISAM but my old tables are InnoDB. Just i changed.

    0 讨论(0)
  • 2020-11-22 07:16

    Perhaps this will help? The definition of the primary key column should be exactly the same as the foreign key column.

    0 讨论(0)
  • 2020-11-22 07:19

    You can get the actual error message by running SHOW ENGINE INNODB STATUS; and then looking for LATEST FOREIGN KEY ERROR in the output.

    Source: answer from another user in a similar question

    0 讨论(0)
  • 2020-11-22 07:19

    I had same issue. It was related to table's column Collation and Character Set. Make sure Character Set and Collation must be same for both columns on two tables. If you want to set a foreign key on that. Example- If you put foreign key on userID column of userImage table referencing userID column of users table.Then Collation must be same that is utf8_general_ci and Character set utf8 for both columns of tables. Generally when you create a table mysql takes these two configuration from server settings.

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