mySql errno: 150 Create table statement inside [duplicate]
DROP TABLE IF EXISTS members;
CREATE TABLE members (
Member_ID char(10) NOT NULL default '',
Provider_ID char(10) NOT NULL default '',
First_开发者_开发知识库Name varchar(30) NOT NULL default '',
Middle_Initial char(1) NOT NULL default '',
Last_Name varchar(40) NOT NULL default '',
Address varchar(100) NOT NULL default '',
City varchar(100) NOT NULL default '',
State char(2) NOT NULL default '',
Zip varchar(5) NOT NULL default '',
PRIMARY KEY (Member_ID),
FOREIGN KEY (PROVIDER_ID) REFERENCES PROVIDER(PROVIDER_ID)
) ;
DROP TABLE IF EXISTS provider;
CREATE TABLE provider (
Provider_ID char(10) NOT NULL default '',
Provider_Name varchar(50) NOT NULL default '',
Address varchar(100) NOT NULL default '',
City varchar(100) NOT NULL default '',
State char(2) NOT NULL default '',
Zip char(5) NOT NULL default '',
PRIMARY KEY (Provider_ID)
) ;
DROP TABLE IF EXISTS procedures;
CREATE TABLE procedures (
Procedure_ID char(10) NOT NULL default '',
Doctor_ID char(10) NOT NULL default '',
Member_ID char(10) NOT NULL default '',
Procedure_Type_ID char(10) NOT NULL default '',
Procedure_Name varchar(50) NOT NULL default '',
Cost int(10) NOT NULL default '0',
Date_Executed date NOT NULL default '2000-01-01',
PRIMARY KEY(Procedure_ID),
FOREIGN KEY(DOCTOR_ID) REFERENCES DOCTOR(DOCTOR_ID),
FOREIGN KEY(MEMBER_ID) REFERENCES MEMBER(MEMBER_ID),
FOREIGN KEY(PROCEDURE_TYPE_ID) REFERENCES PROCEDURE_TYPE(PROCEDURE_TYPE_ID)
) ;
DROP TABLE IF EXISTS procedure_type;
CREATE TABLE procedure_type (
Procedure_Type_ID char(10) NOT NULL default '',
Procedre_Type_Name varchar(50) NOT NULL default '',
Procedure_Description varchar(255) NOT NULL default '',
Procedure_ID char(10) NOT NULL default '',
PRIMARY KEY(Procedure_Type_ID),
FOREIGN KEY(PROCEDURE_ID) REFERENCES PROCEDURES(PROCEDURE_ID)
) ;
DROP TABLE IF EXISTS doctor_type;
CREATE TABLE doctor_type (
Type_ID char(10) NOT NULL default '',
Type_Name varchar(50) NOT NULL default '',
Type_Description varchar(255) NOT NULL default '',
PRIMARY KEY(Type_ID)
) ;
DROP TABLE IF EXISTS doctor;
CREATE TABLE doctor (
Doctor_ID char(10) NOT NULL default '',
Type_ID char(10) NOT NULL default '',
Doctor_Name varchar(50) NOT NULL default '',
Address varchar(100) NOT NULL default '',
City varchar(100) NOT NULL default '',
State char(2) NOT NULL default '',
Zip char(5) NOT NULL default '',
PRIMARY KEY(Doctor_ID),
FOREIGN KEY(TYPE_ID) REFERENCES DOCTOR_TYPE(TYPE_ID)
) ;
ERROR 1005 (HY000): Can't create table 'thunderhawk.members' (errno: 150)
Any ideas?
I know it is a foreign key problem. I seem to be following the foreign key syntax...
This question is a dupe of:
MySQL: Can't create table (errno: 150)
The error message tells you exactly what the problem is: table thunderhawk.members
cannot be created because of error number (errno) 150, a foreign key constraint would be violated:
FOREIGN KEY (PROVIDER_ID) REFERENCES PROVIDER(PROVIDER_ID)
You cannot create the members
table before creating the provider
table, because the members
table has a foreign key dependency on the provider
table.
Usually, If the dbms is not able to create a table that means the following things could have gone wrong: a) The dbms process doesnt has write permission to write in the data directory, or the disk quota for the folder has exceeded. b) file system is full and there is no space to write any data to the file.
Check your mysqld.log for more details.
first thing you need to sure that check that both table need to have same storage type like InnoDB.
see here a reference : http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-create-table-mydbsql-328_45frm-errno-150/
Try this code:
DROP TABLE IF EXISTS members;
CREATE TABLE members (
Member_ID char(10) NOT NULL default 0,
Provider_ID char(10) NOT NULL default 0,
First_Name varchar(30) NOT NULL default 0,
Middle_Initial char(1) NOT NULL default 0,
Last_Name varchar(40) NOT NULL default 0,
Address varchar(100) NOT NULL default 0,
City varchar(100) NOT NULL default 0,
State char(2) NOT NULL default 0,
Zip varchar(5) NOT NULL default 0,
PRIMARY KEY (Member_ID),
FOREIGN KEY (PROVIDER_ID) REFERENCES PROVIDER(PROVIDER_ID)
) ;
精彩评论