Error 1005 Hy000 Cannot Create Table Errno 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
Error 1005 (hy000) (errno 150)
Stack Overflow the company Business Learn more about hiring developers or posting ads with error 1005 (hy000) can't create table error 150 us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is errno 121 mysql a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up ERROR 1005 (HY000): Can't create table (errno: 150) up vote 12 down vote
Mysql Error 1005 Errno 150
favorite 3 I get an error when I try to create a table in mysql. Any tips on resolving it? create table stock_in( ind int not null auto_increment, itemcode varchar(10) not null, quantity int not null, description text not null, sales_ref int not null default -1, return_outwards_ref int not null default -1, stock_in_receipt_ref int not null default -1, date text not null, time text not null, username text not null,
Mysql Errno 150 Can't Create Table
foreign key (sales_ref) references sales (receiptno), foreign key (return_outwards_ref) references returnoutwards(ind), primary key (ind) ); The Error: ERROR 1005 (HY000): Can't create table 'posinventory.stock_in' (errno: 150) mysql share|improve this question edited Jun 15 '12 at 22:38 Austyn Mahoney 7,26943875 asked Jun 15 '12 at 5:52 Boon 1652421 Have you created sales and returnoutwards tables with unique keys? All tables must be InnoDb. –Devart Jun 15 '12 at 6:01 @Devart: Thanks, I found my mistake... it is because the receiptno in sales table is not a primary key... I should reference it to a new column with primary key, for example, sales_no –Boon Jun 15 '12 at 9:37 add a comment| 4 Answers 4 active oldest votes up vote 22 down vote accepted Check out the MySQL manual about foreign key constrains: If you re-create a table that was dropped, it must have a definition that conforms to the foreign key constraints referencing it. It must have the right column names and types, and it must have indexes on the referenced keys, as stated earlier. If these are not satisfied, MySQL returns error number 1005 and refers to error 150 in the error message. A few ideas: Better drop the tables and create it new
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 supports transactions, row-level locking, and foreign keys Us Learn more about Stack Overflow the company Business Learn more about hiring
Error 1005 Mysql
developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join mysql can't create table (errno: -1) the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error Code: 1005. Can't create http://stackoverflow.com/questions/11045279/error-1005-hy000-cant-create-table-errno-150 table '…' (errno: 150) up vote 74 down vote favorite 29 I searched for a solution to this problem on internet and checked the SO questions but no solution worked for my case. I want to create a foreign key from table sira_no to metal_kod. ALTER TABLE sira_no ADD CONSTRAINT METAL_KODU FOREIGN KEY(METAL_KODU) REFERENCES metal_kod(METAL_KODU) ON DELETE SET NULL ON UPDATE SET NULL ; This script http://stackoverflow.com/questions/9018584/error-code-1005-cant-create-table-errno-150 returns: Error Code: 1005. Can't create table 'ebs.#sql-f48_1a3' (errno: 150) I tried adding index to the referenced table: CREATE INDEX METAL_KODU_INDEX ON metal_kod (METAL_KODU); I checked METAL_KODU on both tables (charset and collation). But couldn't find a solution to this problem. Does anyone have any idea? Thanks in advance. EDIT: Here is the metal_kod table: METAL_KODU varchar(4) NO PRI DURUM bit(1) NO METAL_ISMI varchar(30) NO AYAR_YOGUNLUK smallint(6) YES 100 mysql mysql-error-1005 share|improve this question edited Jan 27 '14 at 7:57 Melon 786617 asked Jan 26 '12 at 13:14 lamostreta 85122045 Can you show the schema for the metal_kod table ... which field in that table should the Foreign Key reference ? –ManseUK Jan 26 '12 at 13:28 add a comment| 9 Answers 9 active oldest votes up vote 199 down vote accepted Error Code: 1005 -- there is a wrong primary key reference in your code usually it's due to a reference FK field not exist. might be you have typo mistake,or check case it should be same, or there's a field-type mismatch. FK-linked fields must match definitions exactly. Some Known causes may be : The two key fields type and/or size doesn
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 http://dba.stackexchange.com/questions/62114/create-table-shows-error-1005hy000-errno-150 Overflow the company Business Learn more about hiring developers or posting ads with us https://www.troyfawkes.com/solved-mysql-error-1005-cant-create-table-errno-150/ 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 error 1005 answer The best answers are voted up and rise to the top Create table shows ERROR 1005(HY000) errno 150 up vote 0 down vote favorite i tried to create tables as per given in my textbook in MySQL server as follows: create table department (dept_name varchar(20), building varchar(15), budget numeric(12,2), primary key (dept_name) ); create table course (course_id varchar(8), title varchar(50), dept_name varchar(20), credits numeric(2,0), primary key (course_id), foreign key (dept_name) references can't create table department ); the department table gets created, but an error ERROR 1005 (HY000): Can't create table 'test.course' (errno: 150) is displayed. The queries seem very simple. And i am unable to find any mistake. What can be the possible error that is preventing me to create the table? mysql foreign-key share|improve this question asked Mar 31 '14 at 5:29 Amita 312 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote accepted You are missing column name of parent table to which your child refer, while creating child table, do like below create table department (dept_name varchar(20), building varchar(15), budget numeric(12,2), primary key (dept_name) ); create table course (course_id varchar(8), title varchar(50), dept_name varchar(20), credits numeric(2,0), primary key (course_id), foreign key (dept_name) references department(dept_name) ); share|improve this answer answered Mar 31 '14 at 5:32 Abdul Manaf 4,73563864 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged mysql foreign-key or ask your own qu