Mysql Create Table Error Number 150
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn mysql cannot create table error 150 more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags
Mysql Errno 150 Create Table
Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you,
Mysql Can't Create Table Errno 150
helping each other. Join them; it only takes a minute: Sign up MySQL Foreign Key, Can't create table (errno: 150) up vote 7 down vote favorite 2 I am trying to build the database and tables for my
Mysql Can't Create Table Errno 150 Foreign Key
system. But I found that if I don't add the foreign key in the codes. There is no error. I've used many method try to make the codes works, but it still have error. I am using MySQL 5.5.31, and the codes here: CREATE DATABASE TOS; DROP TABLE TOS.USER CASCADE; DROP TABLE TOS.BILL_HEADER CASCADE; DROP TABLE TOS.TOY CASCADE; CREATE TABLE TOS.USER (User Char(8), Name Char(10), Type Char(1), Password Char(12), PRIMARY KEY(User)); CREATE TABLE TOS.BILL_HEADER (Bill_No Char(10), 1005 can't create table errno 150 CTime DateTime, No_Of INTEGER, Cus_No Char(5), DTime DateTime, PRIMARY KEY(Bill_No)); CREATE TABLE TOS.TOY (Toy_Id Char(10), FullN Char(50), ShortN Char(20), Descrip Char(20), Price DECIMAL, Avail Char(1), Cat Char(1), PRIMARY KEY(Toy_Id)); CREATE TABLE TOS.BILL_ITEM (Bill_No Char(10), BSeq_No INTEGER, Toy_Id Char(10), OTime DateTime, Quan INT, DCondition Char(1), PRIMARY KEY(Bill_No,BSeq_No), FOREIGN KEY(Bill_No) REFERENCES TOS.Bill_Header(Bill_No), FOREIGN KEY(Toy_Id) REFERENCES TOS.TOY(Toy_Id)); Error: 1005 - Can't create table 'TOS.BILL_ITEM' (errno: 150) Any help would be greatly appreciated. mysql foreign-keys mysql-error-1005 share|improve this question asked Nov 23 '13 at 19:06 Confucius 1043310 It does appear to work if I remove the DROP statements.. sqlfiddle.com/#!2/08d1e –Michael Berkowski Nov 23 '13 at 19:10 2 Usually, err 150 is a foreign key error, due to a data type and length mismatch between the column and relation, or a missing index on the primary column. You do have all the correct types and PK indexes defined though. –Michael Berkowski Nov 23 '13 at 19:12 Could you try to remove only one of the foreign keys to narrow the problem? –Oscar Pérez Nov 23 '13 at 19:14 add a comment| 2 Answers 2 active oldest votes up vote 14 down vote accepted The non-descript error 150 is usually related to foreign key data type or length mismatches, or a missing index on the parent table's column. This look s to be a matter of case sensi
here for a quick overview of the site Help Center Detailed answers to any questions you errno 150 mysql foreign key might have Meta Discuss the workings and policies of this site error code: 1005. can't create table (errno: 150) About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or can t create table errno 121 posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of http://stackoverflow.com/questions/20166573/mysql-foreign-key-cant-create-table-errno-150 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up MySQL Errno 150 up vote 18 down vote favorite 4 I'm creating a few simple tables and I can't get passed this foreign key error and I'm not sure why. Here's the script below. create TABLE Instructors http://stackoverflow.com/questions/16227199/mysql-errno-150 ( ID varchar(10), First_Name varchar(50) NOT NULL, Last_Name varchar(50) NOT NULL, PRIMARY KEY (ID) ); create table Courses ( Course_Code varchar(10), Title varchar(50) NOT NULL, PRIMARY KEY (Course_Code) ); create table Sections ( Index_No int, Course_Code varchar(10), Instructor_ID varchar(10), PRIMARY KEY (Index_No), FOREIGN KEY (Course_Code) REFERENCES Courses(Course_Code) ON DELETE cascade ON UPDATE cascade, FOREIGN KEY (Instructor_ID) REFERENCES Instructors(ID) ON DELETE set default ); Error Code: 1005. Can't create table '336_project.sections' (errno: 150) My data types seem identical and the syntax seems correct. Can anyone point out what I'm not seeing here? Thank you! I'm using MySQL Workbench 5.2 mysql table foreign-keys mysql-workbench share|improve this question asked Apr 26 '13 at 1:13 Sixers17 1771211 add a comment| 8 Answers 8 active oldest votes up vote 22 down vote accepted If you're using the InnoDB engine, the ON DELETE SET DEFAULT is your problem. Here's an excerpt from the manual: While SET DEFAULT is allowed by the MySQL Server, it is rejected as
log in tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this http://dba.stackexchange.com/questions/80435/mysql-create-table-shows-error-1005-errno-150 site About Us Learn more about Stack Overflow the company Business Learn more http://dba.stackexchange.com/questions/5437/mysql-foreign-key-cant-create-table-error-150 about hiring developers or posting ads with us Database Administrators Questions Tags Users Badges Unanswered Ask Question _ Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute: create table Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Mysql Create table shows ERROR 1005 errno 150 up vote 0 down vote favorite I am trying to make a junction table, but I getting a ERROR 1005 errno 150 CREATE TABLE 61furiousFistPokemon( cardNumber int NOT NULL PRIMARY KEY, pokemonName t create table VARCHAR(12), type VARCHAR(10), stage VARCHAR(10), evolvesFrom VARCHAR(12), HP INT, retreatCost INT, weakness VARCHAR(10), weaknessAmount VARCHAR(5), resistance VARCHAR(5), resistanceAmount VARCHAR(5) ); CREATE TABLE cardTags ( tagId int NOT NULL AUTO_INCREMENT PRIMARY KEY, tagName VARCHAR(60) NOT NULL ); CREATE TABLE 61furiousFistPokemonTags ( tagId int NOT NULL AUTO_INCREMENT PRIMARY KEY, pokemonCardNumber int, tagName VARCHAR(60), FOREIGN KEY (pokemonCardNumber) REFERENCES 61furiousFistPokemon(cardNumber), FOREIGN KEY (tagName) REFERENCES cardTags(tagName) ); Any help would be greatly appreciated. mysql innodb foreign-key table share|improve this question edited Oct 17 '14 at 15:23 RolandoMySQLDBA 108k15139276 asked Oct 17 '14 at 3:43 user50479 add a comment| 3 Answers 3 active oldest votes up vote 1 down vote tagName column in table cardTags is not defined as primary key and you are declaring foreign key FOREIGN KEY (tagName) REFERENCES cardTags(tagName). share|improve this answer answered Oct 17 '14 at 8:13 Nawaz Sohail 611314 Although you did not provide a solution, +1 for revealing root cause. –RolandoMySQLDBA Oct 17 '14 at 15:19 add a comment| up vote 0 down vote Very often it happens, when the foreign key and the reference key don't have same type or same length. Click here for more details. share|improve this answer
log in tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Database Administrators Questions Tags Users Badges Unanswered Ask Question _ Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top MySQL, foreign key, can't create table error 150 up vote 5 down vote favorite 1 UPDATE: Sorry, it was because i forgot to add UNSIGNED attribute to the lang_id column. Original: I'm trying to create a table with foreign key in MySQL. I get this error: #1005 - Can't create table 'xy.trans' (errno: 150) Any ideas whats wrong with the following create statement? CREATE TABLE IF NOT EXISTS `lang` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `code` CHAR(2) NOT NULL, PRIMARY KEY (`id`) ) ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS `trans` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `something` TEXT NOT NULL, `lang_id` INT NULL, PRIMARY KEY (`id`), INDEX `index_trans_lang` (`lang_id` ASC), CONSTRAINT `fk_trans_lang` FOREIGN KEY (`lang_id` ) REFERENCES `lang` (`id` ) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE = InnoDB; mysql foreign-key share|improve this question edited Jan 14 '13 at 12:07 Akash 542318 asked Sep 6 '11 at 10:39 Ben 2613 Ah, +1 for solving your own problem !!! –RolandoMySQLDBA Sep 6 '11 at 15:00 3 @Ben, if you would be so kind as to post your answer as an answer proper, and mark it accepted, you'll get upvotes (higher rep) and it'll be more clear what transpired here. –jcolebrand♦ Sep 6 '11 at 18:08 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote I've had a similar problem with this, and I finally resolved it by checking the field types of the two fields that were being referenced - they have to be exactly the same type - all the way down to the "Not NUll" and "Unsigned" settings... In your original post, the "lang" table has the "id" field defined as "INT UNSIGNED NOT NULL", whereas the "trans" table has the "lang_id" field defined as "INT NULL"... share|improve this answer answered Sep 2