Error 1005 Errno 150 Mysql
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have mysql foreign key Meta Discuss the workings and policies of this site About Us
Sql Error 1005 Errno 150
Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with error 1005 (hy000) errno 150 us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just mysql can't create table error 150 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 four columns: (Comune, Via, Civico, Immobile). Now,
Mysql Error 1005 Can't Create Table
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`) , CONSTRAINT `ComuneImmobile` FOREIGN KEY (`ComuneImmobile` ) REFERENCES `dbimmobili`.`Immobile` (`ComuneImmobile` ) ON DELETE CASCADE ON UPDA
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies mysql error 1005 errno 121 of this site About Us Learn more about Stack Overflow the company error 1005 iphone Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges
Error 1005 Archeage
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 http://stackoverflow.com/questions/4063141/mysql-foreign-key-error-1005-errno-150 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) REFERENCES Route(routeNo) http://stackoverflow.com/questions/34074739/mysql-error-1005-errno-150-foreign-key-constraint-is-incorrectly-formed ); 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 (routeNo) REFERENCES Stop(routeNo), CONSTRAINT fk_Stops F
Community Podcasts MySQL.com Downloads Documentation Section Menu: MySQL Forums :: InnoDB :: ERROR 1005: Can't create table (errno: 150) New Topic Advanced Search Re: ERROR 1005: Can't create table (errno: 150) Posted by: Chetan Dhumale () Date: November http://forums.mysql.com/read.php?22,19755,499517 18, 2011 12:31AM Dear All I also got the same error #1005 can't create table errno 150 mysql error because of incorrect foreign key. I search online. I first take that table(child table) and the tables(master tables) which it refers separate from database . correct the data types and make sure foreign key and referenced column should have same data types, length, attributes, default values, collation. and then my problem is error 1005 solved. i got the hint from mysql ref manual link: http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html Navigate:Previous Message•Next Message Options:Reply•Quote Subject Views Written By Posted ERROR 1005: Can't create table (errno: 150) 641045 elmpie 03/24/2005 01:20PM Re: ERROR 1005: Can't create table (errno: 150) 304077 Martin Lukasiewycz 03/28/2005 02:15PM Re: ERROR 1005: Can't create table (errno: 150) 215415 KimSeong Loh 03/29/2005 08:42PM Re: ERROR 1005: Can't create table (errno: 150) 155609 Michael Buell 05/30/2005 10:29AM Re: ERROR error 1005 errno 1005: Can't create table (errno: 150) 149723 Chris Yuan 10/27/2005 11:01PM Re: ERROR 1005: Can't create table (errno: 150) 92335 Deepak Kumar 03/14/2008 11:45PM ERROR 1005: Can't create table (errno: 150) 72373 Pradeep Max 07/07/2008 09:00AM Re: ERROR 1005: Can't create table (errno: 150) 49758 karthik sakthi 03/12/2009 07:38AM Re: ERROR 1005: Can't create table (errno: 150) Global solution 50899 Mayur P Vegad 06/23/2010 08:13AM Re: ERROR 1005: Can't create table (errno: 150) Global solution 20525 B S 08/13/2011 09:04PM unfortunately not 4824 Gavin Stokes 10/09/2012 09:48PM Re: ERROR 1005: Can't create table (errno: 150) 37427 Agyeya Gupta 04/26/2009 06:23AM Re: ERROR 1005: Can't create table (errno: 150) 25611 Chris Walker 06/28/2009 12:40PM Re: ERROR 1005: Can't create table (errno: 150) [SOLVED] 48481 Chris Walker 06/28/2009 12:41PM Re: ERROR 1005: Can't create table (errno: 150) [SOLVED] 29138 Jitendra Gupta 09/04/2009 02:30AM Re: ERROR 1005: Can't create table (errno: 150) [ANOTHER SOLUTION] 29783 Jim Smith 01/11/2010 10:23AM Re: ERROR 1005: Can't create table (errno: 150) [ANOTHER SOLUTION] 11108 Esen Sagynov 04/17/2011 05:39AM Re: ERROR 1005: Can't create table (errno: 150) [SOLVED] 12537 noor afies prasetyo 11/03/2010 10:10PM Re: ERROR 1005: Can't create table (errno: 150) [SOLVED] 2251 marius m 12/17/2012 07:52AM Re: ERROR 1005: Can't create table (errno: 150) [SOLUTION] 17868 Stefan