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

Improve FK constraint error messages was: Foreign key constraint is incorrectly formed on 11.4.2. It works on 10.11.7

    XMLWordPrintable

Details

    • Bug
    • Status: Stalled (View Workflow)
    • Major
    • Resolution: Unresolved
    • 11.4.2, 10.5, 10.6, 10.11, 11.4
    • 10.5, 10.6, 10.11, 11.4
    • docker run --detach --publish 3306:3306 --name mariadb --env MARIADB_ROOT_PASSWORD='...' mariadb
      # on M3Max Macbook Pro

    Description

      The following code works on RDS MariaDB version 10.11.7 and fails on MariaDB version 11.4.2-MariaDB-ubu2404 with

      [HY000][1005] (conn=6) Can't create table `kasaExample`.`projection` (errno: 150 "Foreign key constraint is incorrectly formed")

      I can create the table on 11.4.2 if I remove either:

      constraint fk_projection_project foreign key ( projectId ) references project( id )

      or

      unique un_Projection_oneActivePerProject( oneActive ) ignored

      I see no issue with either of the two definitions or their combination.

      The following is a stand-alone code.

      drop schema if exists kasaExample;
      create schema if not exists kasaExample;
      use kasaExample;
       
      create table project(
          id   serial          primary key,
          name text   not null unique     ,
          note text
      ) with system versioning;
       
      create table projection(
          id        serial          primary key,
          projectId bigint unsigned not null   , constraint fk_projection_project foreign key ( projectId ) references project( id ),
          isActive  boolean         not null     default false comment 'Is this the actively used projection for real world payments and expectations or just a regular test projection?',
          name      varchar( 768 )  not null   ,
          note      text                       ,
          oneActive bigint unsigned as ( if( isActive, projectId, null ) ) invisible,
              unique un_Projection_oneActivePerProject( oneActive ) ignored,
              unique un_projectionName_per_project( projectId, name )
      ) with system versioning;
      

      Attachments

        Issue Links

          Activity

            People

              nikitamalyavin Nikita Malyavin
              Dimitar Dimitar Gologanov
              Votes:
              0 Vote for this issue
              Watchers:
              5 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.