MySQL error 150, cannot create table

孤街醉人 提交于 2019-11-28 12:42:55

Check that Gebruikers_gebruiker_id and Gebruikers.gebruiker_id have same datatype.

Also check that Gebruikers.gebruiker_id is a PRIMARY KEY in Gebruikers

Update:

You have ON DELETE SET NULL defined, while your Gebruikers_gebruiker_id is defined as NOT NULL.

Fix it (change to ON DELETE CASCADE or just remove the clause) and you'll be able to create the reference.

Im my case its typically because of a datatype mismatch. Remember if it is an int check that both are either unsigned or not

This is'nt much a buggy characteristic of mysql. There can be two possible reasons for this! 1) the datatypes of the PK and the FK dont match. 2) This error can come up in versions prior to 4.1 where you need to explicitly define indexes.

One more reason to add:

Different charset or engine will also cause this problem

In my person experience this a very buggy characteristic of MySQL - and the least hassle is to just dump the table structure and data, then drop the table and re-run the SQL from the dump and then manually re-create indexes and foreign key constraints where needed.

I had a constraint with the same name in a different table. Try changing the name of your constraint.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!