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

cannot drop column with foreign key constraint

    XMLWordPrintable

Details

    Description

      CREATE TABLE `tab1` (
        `tab1id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `tab1desc` varchar(60) NOT NULL,
        PRIMARY KEY (`tab1id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
       
      CREATE TABLE `tab2` (
        `tab2id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `tab1id` int(10) unsigned DEFAULT NULL,
        `tab2desc` varchar(60) NOT NULL,
        PRIMARY KEY (`tab2id`),
        KEY `idxtab2tab1id` (`tab1id`),
        CONSTRAINT `fktab2tab1id` FOREIGN KEY (`tab1id`) REFERENCES `tab1` (`tab1id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
      

      dropping tab1id failed:

      alter table tab2 drop COLUMN tab1id;

      Cannot drop index 'idxtab2tab1id': needed in a foreign key constraint

      I can resolve by drop constraint first, but it is not fine

      Attachments

        Activity

          People

            serg Sergei Golubchik
            svh Stefan van Hasselt
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.