MySQL. Can't create table errno 150

前端 未结 22 1153
广开言路
广开言路 2020-12-01 09:59

I have to create a database with two tables in MySQL, but the script fails with errno 150 (foreign key problem). I double-checked the foreign key fields to be the same on bo

相关标签:
22条回答
  • In my case I got old table definition MyISAM in one of the tables and obviously I was unable to make foreign key to it from another table. Maybe this help someone.

    So this may happen because of inconsistencies between two databases/fields definitions try to check:

    Field Type
    Field Collation
    Table Engine
    
    0 讨论(0)
  • 2020-12-01 10:58

    If nothing works, try this:

    The foreign key name is a duplicate of an already existing key. Check that the name of your foreign key is unique within your database. Just add a few random characters to the end of your key name to test for this.

    0 讨论(0)
  • 2020-12-01 10:58

    I was using MySQL workBench. THe issue is you cannot use the same foreign key name, they need to be unique. So if more than one table will reference the same foreign key, each time there must be a unique name given.

    0 讨论(0)
  • 2020-12-01 10:58

    If you are working on mysql workbench and you get this error for a relationship table there may be a quick fix for you: just delete it and let mysql workbench recreate it for you. Then copy the sql. Fixed my errno 150 problem.

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