Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-15868

'CREATE TABLE t3 LIKE t2' drops foreign key constraint

    XMLWordPrintable

Details

    Description

      Simple Example:

      create table t1(f1 int ,primary key(f1))engine=innodb;
      create table t2(f2 int,f3 int, key t(f2),key t1(f2,f3),foreign key(f2) references t1(f1))engine=innodb;
      create table t3 LIKE t2;
      SHOW CREATE TABLE t2;
      SHOW CREATE TABLE t3;
      

      `SHOW CREATE TABLE t2;` is correct:

      CREATE TABLE `t2` (
        `f2` int(11) DEFAULT NULL,
        `f3` int(11) DEFAULT NULL,
        KEY `t` (`f2`),
        KEY `t1` (`f2`,`f3`),
        CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
      

      'SHOW CREATE TABLE t3;' shows that t3 is missing the foreign key constraint:

      CREATE TABLE `t3` (
        `f2` int(11) DEFAULT NULL,
        `f3` int(11) DEFAULT NULL,
        KEY `t` (`f2`),
        KEY `t1` (`f2`,`f3`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
      

      Attachments

        Activity

          People

            greenman Ian Gilfillan
            SeparateReality T.Peter
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.