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

Adding Constraint with no database reference results in ERROR 1046 (3D000) at line 13: No database selected

    XMLWordPrintable

Details

    Description

      When creating a table with a constraint which references a table without explicitly naming the database the statement fails with the following error.

      ERROR 1046 (3D000) at line ##@ No database selected.
      

      The test statement used is as follows:

      CREATE TABLE `kg_test1`.`person` 
      (
       `Id` INT(11) NOT NULL AUTO_INCREMENT,
       `Name` VARCHAR(50) NOT NULL,
        PRIMARY KEY (`Id`),
        CONSTRAINT `fk_person_group` FOREIGN KEY (`Id`) REFERENCES `group` (`Id`)
      ) ENGINE=INNODB DEFAULT CHARSET=utf8;
      

      I'm using a local client to connect and run the test statement on MariaDB 5.5.41 - 46, on both Windows 2012 & CentOS 6.7....which all fail with the same error as above.

      You can work around this by either adding a database name to the reference, (kg_test1.group) or adding database context (i.e. use <db-name>) when logging in via the client, but it does not have to be the same database the table is being created in.

      This is a change in behaviour to MariaDB verisons prior to 5.5.41.

      Attachments

        Activity

          People

            jplindst Jan Lindström (Inactive)
            martin.walsh Martin Walsh
            Votes:
            0 Vote for this issue
            Watchers:
            4 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.