[MDEV-19891] CREATE TABLE statement printed by SHOW CREATE TABLE fails with (errno: 150 "Foreign key constraint is incorrectly formed") Created: 2019-06-27  Updated: 2019-07-05  Resolved: 2019-07-05

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Create Table
Affects Version/s: 10.3.15, 10.4.6
Fix Version/s: 10.3.15

Type: Bug Priority: Major
Reporter: Ulrich Moser (Inactive) Assignee: Anel Husakovic
Resolution: Not a Bug Votes: 0
Labels: need_feedback
Environment:

Ubuntu Server 18.04 LTS and MariaDB 10.4.6
Ubuntu Server 16.04 LTS and MariaDB 10.3.15



 Description   

When I issue SHOW CREATE TABLE city in the world sample database and take that statement to create an identical table in a different schema I get the error mentioned above.

MariaDB [world]> show create table city\G
*************************** 1. row ***************************
       Table: city
Create Table: CREATE TABLE `city` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Name` char(35) NOT NULL DEFAULT '',
  `CountryCode` char(3) NOT NULL DEFAULT '',
  `District` char(20) NOT NULL DEFAULT '',
  `Population` int(11) NOT NULL DEFAULT 0,
  PRIMARY KEY (`ID`),
  KEY `CountryCode` (`CountryCode`),
  CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES `country` (`Code`)
) ENGINE=InnoDB AUTO_INCREMENT=4095 DEFAULT CHARSET=latin1
1 row in set (0.000 sec)
 
MariaDB [world2]> CREATE TABLE `city` (
    ->   `ID` int(11) NOT NULL AUTO_INCREMENT,
    ->   `Name` char(35) NOT NULL DEFAULT '',
    ->   `CountryCode` char(3) NOT NULL DEFAULT '',
    ->   `District` char(20) NOT NULL DEFAULT '',
    ->   `Population` int(11) NOT NULL DEFAULT 0,
    ->   PRIMARY KEY (`ID`),
    ->   KEY `CountryCode` (`CountryCode`),
    ->   CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES `country` (`Code`)
    -> ) ENGINE=InnoDB AUTO_INCREMENT=4095 DEFAULT CHARSET=latin1;
ERROR 1005 (HY000): Can't create table `world2`.`city` (errno: 150 "Foreign key constraint is incorrectly formed")



 Comments   
Comment by Anel Husakovic [ 2019-06-27 ]

Hi umoser,
I suppose you have defined in `world2` table `country` right?
Can you paste the `show create table country` in `world2` ?

Comment by Anel Husakovic [ 2019-07-03 ]

Hi umoser,
any update regarding this MDEV ?

Comment by Ulrich Moser (Inactive) [ 2019-07-05 ]

No idea what the reason was. Tried the same the other day and it worked.

Generated at Thu Feb 08 08:55:09 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.