MySQL Forums
Forum List  »  InnoDB

Re: ERROR 1005: Can't create table (errno: 150) (Potential solution)
Posted by: Niranjan Hoskote
Date: March 02, 2010 02:06PM

The field being referenced as a FK, in the PARENT table, needs to be
1) either a AI or UQ
2) It has to be the same "data type" and equal in ALL respects (VARCHAR(xx)) in BOTH the field in the parent table and the FK in the child table
3) Make sure that the "Collation" is ALSO the same (latin 1 or UTF8 are the most common ones). To ensure sanity make everything the same (you can do this at the table level or at field level). BUT what is critical is that the parent AND child tables have to be the same, IF NOT the field in the parent table and the FK field in the child table has to be the same.
4) Engine has to be InnoDB
5) IF you are using a field from a table as a FK in more than one table, then make sure that the "Foreign Key Name" (a column in the MySQL Workbench) is unique. IF you use the same FK Name, it will fail.

I am a real newbie, but that is what my research has led me to.

(Also, I find it extremely hard to believe that no one has collated a better error manual for MySQL!!!!!! Strange that after years we still have the same meaningless error messages. Why is that the process that was inserting, updating, whatever could throw an error message but could not spit out a more meaningful one, I have no idea. These are fairly trivial things.)

Best .............

N-



Edited 3 time(s). Last edit at 03/05/2010 09:24AM by Niranjan Hoskote.

Options: ReplyQuote


Subject
Views
Written By
Posted
652709
March 24, 2005 01:20PM
5957
October 09, 2012 09:48PM
4123
December 19, 2011 10:13PM
9693
May 09, 2006 06:01PM
12921
November 15, 2006 02:05PM
7820
T D
February 01, 2008 06:47AM
9815
August 27, 2008 08:08AM
10132
December 03, 2008 10:15AM
6576
May 01, 2009 07:39AM
3859
August 29, 2011 04:46PM
5513
s l
December 15, 2009 01:48PM
5381
December 22, 2009 02:54AM
Re: ERROR 1005: Can't create table (errno: 150) (Potential solution)
6870
March 02, 2010 02:06PM
3622
February 18, 2011 08:55AM
4395
May 24, 2011 10:11AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.