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

Cannot modify a column if there is a generated column before it and a foreign key

    XMLWordPrintable

Details

    Description

      Trying to modify a column that is not part of any foreign key throws an error that the column can not be modified because it is part of a foreign key.
      The prerequisites for the bug to manifest is to have a foreign key to another table for another column and a generated column before the column you are tryging to modify.

      Here is a simple script to reproduce:

      DROP TABLE IF EXISTS b_poses;
      DROP TABLE IF EXISTS b_users;
       
      CREATE TABLE `b_users` (
        `USER_ID` int(11) NOT NULL AUTO_INCREMENT,
        PRIMARY KEY (`USER_ID`)
       );
       
      CREATE TABLE `b_poses` (
        `POS_ID` int(11) NOT NULL AUTO_INCREMENT,
        `DELETE_FLAG` tinyint(1) NOT NULL DEFAULT 0,
        `DEL_UNQ` char(0) GENERATED ALWAYS AS (if(`DELETE_FLAG` = 0,'',NULL)) STORED,
        `FOR_USER_ID` int(11) DEFAULT NULL,
        `XRANDR_PRIMARY` varchar(10) NOT NULL DEFAULT '',
        PRIMARY KEY (`POS_ID`),
        KEY `b_poses_fk11` (`FOR_USER_ID`),
        CONSTRAINT `b_poses_fk11` FOREIGN KEY (`FOR_USER_ID`) REFERENCES `b_users` (`USER_ID`) ON DELETE CASCADE
      );
       
      ALTER TABLE b_poses MODIFY COLUMN XRANDR_PRIMARY VARCHAR(25) NOT NULL DEFAULT '';
      

      This throws an error

      ERROR 1832 (HY000) at line 20: Cannot change column 'XRANDR_PRIMARY': used in a foreign key constraint 'test/b_poses_fk11'


      If we move the generated column after the column we are trying to change the operation is successful.
      The operation is also successful if instead of trying to make the column bigger we make it lower.

      Attachments

        Activity

          People

            nikitamalyavin Nikita Malyavin
            lukav Anton Avramov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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