Bug #41635 | Create table returns errno 150 when you include a FK in the table definition | ||
---|---|---|---|
Submitted: | 19 Dec 2008 12:17 | Modified: | 4 Mar 2009 19:26 |
Reporter: | Daniel Ellis | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | Connector / NET | Severity: | S2 (Serious) |
Version: | 5.2.5 | OS: | Windows |
Assigned to: | CPU Architecture: | Any |
[19 Dec 2008 12:17]
Daniel Ellis
[19 Dec 2008 15:31]
Tonci Grgin
Hi Daniel and thanks for your report. Truly what happens is exactly what you described... Error 150 with message can't create table1, weird. At the same time, same command passes in mysql cl client. MySqlConnection conn = new MySqlConnection(); conn.ConnectionString = "DataSource=localhost;Database=test;UserID=root;Password=****;PORT=****;Allow Batch=True;logging=True;Allow User Variables=True"; conn.Open(); try { MySqlCommand cmd = new MySqlCommand(); cmd.CommandType = CommandType.Text; cmd.Connection = conn; cmd.CommandText = "USE test; DROP TABLE IF EXISTS `test2`; DROP TABLE IF EXISTS `test1`; CREATE TABLE `test1`(`id` int NOT NULL PRIMARY KEY) ENGINE=InnoDB; CREATE TABLE `test2`(`id` int NOT NULL PRIMARY KEY,`id_ref` int, CONSTRAINT `test2_ibfk_1` FOREIGN KEY (`id_ref`) REFERENCES `test1`(`id`)) ENGINE=InnoDB;"; cmd.ExecuteNonQuery(); } catch (Exception ex) { Assert.Fail(ex.Message); } Console.ReadLine();
[21 Dec 2008 19:57]
Tonci Grgin
This could be related to Bug#1080 in case c/NET adds some constraints.
[4 Mar 2009 19:26]
Reggie Burnett
This is not a bug. The MySQL command line client breaks up commands on the delimiter. So the first create table is executed and then the second. Connector/net doesn't do that. It recognizes that the server supports batching and sends all the commands at once. This fails in this case. The use has two options. Either execute the two create table statements separately or use the new MySQLScript class.
[4 Apr 2009 23:56]
Jaka JanÄar
Hi, I don't agree that this is not a bug. I don't see any mention of any such limitations in the manual. Even more, the manual [1] even gives an example of using CREATE TABLE with multi-statements. Example of the problem using the CLI client: DELIMITER $ CREATE TABLE a (id INT PRIMARY KEY) ENGINE=InnoDB; CREATE TABLE b (aId INT, FOREIGN KEY (aId) REFERENCES a(id) ON DELETE SET NULL) ENGINE=InnoDB; $ >ERROR 1005 (HY000): Can't create table 'jaka_sandbox2.a' (errno: 150) From SHOW ENGINE INNODB STATUS: > 090405 1:50:12 Error in foreign key constraint of table jaka_sandbox2/a: > FOREIGN KEY (aId) REFERENCES a(id) ON DELETE SET NULL) ENGINE=InnoDB: > Cannot resolve column name close to: > ) REFERENCES a(id) ON DELETE SET NULL) ENGINE=InnoDB [1] http://dev.mysql.com/doc/refman/5.0/en/c-api-multiple-queries.html