Error 1005 Hy000 Errno 150
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you mysql error 1005 errno 150 might have Meta Discuss the workings and policies of this site
Mysql Error 1005 Hy000 Can T Create Table Errno 150
About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or error 1005 hy000 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
Mysql Error Code 1005 Errno 150
4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up MySQL Foreign Key Error 1005 errno 150 up vote 31 down vote favorite 8 I'm doing a small DataBase with MySQL Workbench. I have a main table, called "Immobili", which has a Primary Key composed by mysql error 1005 can't create table four columns: (Comune, Via, Civico, Immobile). Now, I also have three other tables, wich have the same primary key (Comune, Via, Civico, Immobile), but these fields are also referenced to the table Immobili. First question: Can I make a Primary Key that is also a Foreign Key? Second Question: When I try to export the changes it says: Executing SQL script in server # ERROR: Error 1005: Can't create table 'dbimmobili.condoni' (errno: 150) CREATE TABLE IF NOT EXISTS `dbimmobili`.`Condoni` ( `ComuneImmobile` VARCHAR(50) NOT NULL , `ViaImmobile` VARCHAR(50) NOT NULL , `CivicoImmobile` VARCHAR(5) NOT NULL , `InternoImmobile` VARCHAR(3) NOT NULL , `ProtocolloNumero` VARCHAR(15) NULL , `DataRichiestaSanatoria` DATE NULL , `DataSanatoria` DATE NULL , `SullePartiEsclusive` TINYINT(1) NULL , `SullePartiComuni` TINYINT(1) NULL , `OblazioneInEuro` DOUBLE NULL , `TecnicoOblazione` VARCHAR(45) NULL , `TelefonoTecnico` VARCHAR(15) NULL , INDEX `ComuneImmobile` (`ComuneImmobile` ASC) , INDEX `ViaImmobile` (`ViaImmobile` ASC) , INDEX `CivicoImmobile` (`CivicoImmobile` ASC) , INDEX `InternoImmobile` (`InternoImmobile` ASC) , PRIMARY KEY (`ComuneImmobile`, `ViaImmobile`, `CivicoImmobile`, `InternoImmobile`) , CONS
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
Error 1005 (hy000) Can't Create Table Error 150
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs
Error 1005 Cloudflare
Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, errno 121 mysql just like you, helping each other. Join them; it only takes a minute: Sign up Foreign key issue:ERROR 1005 (HY000): Can't create table (errno: 150) up vote 0 down vote favorite I'm getting this error: ERROR 1005 http://stackoverflow.com/questions/4063141/mysql-foreign-key-error-1005-errno-150 (HY000): Can't create table (errno: 150); I know it has something to do with the foreign keys but I have checked to see if they have the same info types etc and I can't find the problem. The video, director actor, role and member create; the rest do not. CREATE TABLE IF NOT EXISTS actor ( actorNo VARCHAR(15) NOT NULL, actorName VARCHAR(40) NOT NULL, PRIMARY KEY (actorNo) ) ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS http://stackoverflow.com/questions/19743728/foreign-key-issueerror-1005-hy000-cant-create-table-errno-150 staff ( StaffNo VARCHAR (15) NOT NULL, name VARCHAR(40) NOT NULL, position VARCHAR(40) , salary FLOAT(5,2) , branchNo VARCHAR(15) NOT NULL, FOREIGN KEY (branchNo) REFERENCES branch(branchNo), UNIQUE KEY (name,branchNo) ) ENGINE=InnoDB; SHOW TABLES; CREATE TABLE IF NOT EXISTS branch ( branchNo VARCHAR(15) NOT NULL, Street VARCHAR (40) , City VARCHAR (20) , State VARCHAR (40) , zipCode VARCHAR (6) NOT NULL, StaffNo VARCHAR (15) NOT NULL, PRIMARY KEY (branchNo), UNIQUE KEY (zipCode), FOREIGN KEY (StaffNo) REFERENCES staff (StaffNo) ON DELETE NO ACTION ON UPDATE CASCADE) ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS director ( directorNo VARCHAR(15) NOT NULL, directorName VARCHAR(40) NOT NULL, PRIMARY KEY (directorNo) ) ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS member ( fName VARCHAR(20) , lName VARCHAR(20) , address VARCHAR (100) , memberNo VARCHAR(15) NOT NULL, PRIMARY KEY (memberNo), UNIQUE KEY `CCfnmLnmAddr` (fName,lName,address) ) ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS registration ( branchNo VARCHAR (15) NOT NULL, memberNo VARCHAR (15) NOT NULL, StaffNo VARCHAR (15) NOT NULL, dateJoined date NOT NULL, PRIMARY KEY (branchNo, memberNo), FOREIGN KEY (memberNo) REFERENCES member (memberNo) ON DELETE SET NULL ON UPDATE CASCADE, FOREIGN KEY (StaffNo) REFERENCES staff (StaffNo) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS videoforrent ( videoNo INT(15) NOT NULL, available CHAR(1) NOT NULL, catalogNo VARCHAR (15) , branchNo VARCHAR(15) NOT NULL, PRIMARY KEY (videoNo), UNIQ
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies http://stackoverflow.com/questions/2799021/mysql-error-1005-hy000-cant-create-table-foo-sql-12c-4-errno-150 of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges https://www.troyfawkes.com/solved-mysql-error-1005-cant-create-table-errno-150/ Ask Question x Dismiss Join 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 error 1005 minute: Sign up MySQL “ERROR 1005 (HY000): Can't create table 'foo.#sql-12c_4' (errno: 150)” up vote 38 down vote favorite 5 I was working on creating some tables in database foo, but every time I end up with errno 150 regarding the foreign key. Firstly, here's my code for creating tables: CREATE TABLE Clients ( client_id CHAR(10) NOT NULL , client_name CHAR(50) NOT error 1005 hy000 NULL , provisional_license_num CHAR(50) NOT NULL , client_address CHAR(50) NULL , client_city CHAR(50) NULL , client_county CHAR(50) NULL , client_zip CHAR(10) NULL , client_phone INT NULL , client_email CHAR(255) NULL , client_dob DATETIME NULL , test_attempts INT NULL ); CREATE TABLE Applications ( application_id CHAR(10) NOT NULL , office_id INT NOT NULL , client_id CHAR(10) NOT NULL , instructor_id CHAR(10) NOT NULL , car_id CHAR(10) NOT NULL , application_date DATETIME NULL ); CREATE TABLE Instructors ( instructor_id CHAR(10) NOT NULL , office_id INT NOT NULL , instructor_name CHAR(50) NOT NULL , instructor_address CHAR(50) NULL , instructor_city CHAR(50) NULL , instructor_county CHAR(50) NULL , instructor_zip CHAR(10) NULL , instructor_phone INT NULL , instructor_email CHAR(255) NULL , instructor_dob DATETIME NULL , lessons_given INT NULL ); CREATE TABLE Cars ( car_id CHAR(10) NOT NULL , office_id INT NOT NULL , engine_serial_num CHAR(10) NULL , registration_num CHAR(10) NULL , car_make CHAR(50) NULL , car_model CHAR(50) NULL ); CREATE TABLE Offices ( office_id INT NOT NULL , office_address CHAR(50) NULL , office_city CHAR(50) NULL , office_County CHAR(50) NULL , office_zip CHAR(10) NULL , office_phone INT NULL , office_email CHAR(255
Communication Skills Training Interpersonal Skills Training Blog About Blog Troy Fawkes / Archives / Solved: MySQL ERROR 1005: Can't create table (errno: 150) (Foreign Key) Nov 27 Solved: MySQL ERROR 1005: Can't create table (errno: 150) (Foreign Key) November 27, 2011 Troy Fawkes 8 Comments Archives Share on Facebook Share 0 Share on TwitterTweet 0 Share on Google Plus Share 0 Share on Pinterest Share 0 Share on LinkedIn Share 0 This is another stupid error. It has to do with trying to successfully set foreign keys in MySQL. ERROR 1005: Can't create table (errno: 150) Great, that's fantastic. Here's an example of where this error will occur. CREATE TABLE main(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id)
);
CREATE TABLE other(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
main_id INT NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(main_id) REFERENCES main(id)
); So I'm trying to make the table "other" reference the table "main" through the foreign key "main_id" and, if you try it, it'll throw an Error 150. Want the solution? The foreign key "main_id" has to have the exact same type as the primary key that it references. In the example, "main_id" in the table "other" has the type INT NOT NULL while "id" in the table "main" has the type "INT UNSIGNED NOT NULL" and also AUTO_INCREMENT, but that isn't something we have to worry about. To make things incredibly clear, here's the working example. CREATE TABLE main( id INT UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY(id) ); CREATE TABLE other( id INT UNSIGNED NOT NULL AUTO_INCREMENT, main_id INT UNSIGNED NOT NULL, PRIMARY KEY(id), FOREIGN KEY(main_id) REFERENCES main(id) ); To solve ‘MySQL ERROR 1005: Can't create table (errno: 150)‘ you likely just have to ensure that your foreign key has the exact same type as the primary key. Hope it helps. Share on Facebook Share 0 Share on TwitterTweet 0 Share on Google Plus Share 0 Share on Pinterest Share 0 Share on LinkedIn Share 0 Facebook Twitter Tumblr Pinterest Google+ LinkedIn E-Mail About The Author My name is Troy Boileau but I go by Troy Fawkes. I'm a digital marketer working in Toronto. On top of that, my passions include social skills, networking and dating; subjects that I've been semi-professionally involved with for almost five years. Top LinksGet The Conversation Handbook How To Improve Conversation Skills How to Speak Clearly & Confidently Communication