Error 1005
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
Error 1005 Archeage
this site About Us Learn more about Stack Overflow the company Business Learn mysql error 1005 more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
Netflix Error 1005
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 minute: Sign up error 1005 can't create table 'db' (errno 13) 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 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 error 1005 can't create table (errno 150) 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`) , CONSTRAINT `ComuneImmobile` FOREIGN KEY (`ComuneImmobile` ) REFERENCES `dbimmobili`.`Immobile` (`ComuneImmobile` ) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ViaImmobile` FOREIGN KEY (`ViaImmobile` ) REFERENCES `dbimmobili`.`Immobile` (`ViaImmobile` ) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `CivicoImmobile` FOREIGN KEY (`CivicoImmobile` ) REFERENCES `dbimmobili`.`Immobile` (`CivicoImmobile` ) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `InternoImmobile` FOREIGN KEY (`InternoImmobile` ) REFERENCES `dbimmobili`.`Immobile` (`InternoImm
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and
Error 1005 The Program Is Missing The Ghostscript Component
policies of this site About Us Learn more about Stack Overflow the error 1005 (hy000) can't create table company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags
Error 1005 (hy000) Can't Create Table (errno 150)
Users Badges 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 http://stackoverflow.com/questions/4063141/mysql-foreign-key-error-1005-errno-150 a minute: Sign up MySQL error 1005 errno 150 Foreign key constraint is incorrectly formed up vote 0 down vote favorite I have created the following tables: Stops: CREATE TABLE Stop ( routeNo DECIMAL (4,0) UNSIGNED, stopNo DECIMAL(3,0) UNSIGNED, latitude DECIMAL(19,16), longitude DECIMAL(19,16), CONSTRAINT PK_Location PRIMARY KEY (routeNo, stopNo), CONSTRAINT FK_stop_location FOREIGN KEY (latitude,longitude) REFERENCES Location(latitude,longitude), CONSTRAINT FK_stop_route FOREIGN KEY (routeNo) http://stackoverflow.com/questions/34074739/mysql-error-1005-errno-150-foreign-key-constraint-is-incorrectly-formed REFERENCES Route(routeNo) ); And the table WorkDay: CREATE TABLE Workday ( theDate DATE PRIMARY KEY, notes VARCHAR(30) ); I then try to create the table Order Delivery with the following code: CREATE TABLE OrderDelivery ( routeNo DECIMAL(4,0) UNSIGNED, stopNO DECIMAL(3,0) UNSIGNED, orderNo INT(9), CONSTRAINT pk_Orders PRIMARY KEY (routeNo, stopNo, orderNo), deliveryDateExpected DATE, deliveryTime TIME, customerName VARCHAR(40), creditCardNo CHAR(16) NOT NULL, customerRanking ENUM('platinum','gold','occasional','one-off'), CONSTRAINT fk_Routes FOREIGN KEY (routeNo) REFERENCES Stop(routeNo), CONSTRAINT fk_Stops FOREIGN KEY (stopNo) REFERENCES Stop(stopNo), CONSTRAINT fk_Dates FOREIGN KEY (deliveryDateExpected) REFERENCES Workday(theDate) ); However every time i try to create the OrderDelivery table it gives the error that the foreign key is incorrectly formed "SQL Error (1005): Can't create table 'harry.OrderDelivery' (errno:150)Foreign key constraint is incorrectly formed" How can i rectify this? mysql share|improve this question asked Dec 3 '15 at 19:40 HarAdams 92 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote You can't create a foreign key to a table with a multiple primary key referencing only one field of that primary key. So your problem lies here: CONSTRAINT fk_Routes FOREIGN KEY (routeN
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 https://www.troyfawkes.com/solved-mysql-error-1005-cant-create-table-errno-150/ 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 error 1005 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 can't create table 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, networ