6

I have a problem with those lines on my MAC, on mariaDB 10.4.11 version.

DROP DATABASE IF EXISTS Employe_Programmeurs;
CREATE DATABASE Employe_Programmeurs;
USE Employe_Programmeurs;

CREATE TABLE Employe(
    noEmp      INT(5),
    nom        VARCHAR(10),
    prenom     VARCHAR(10),
    CONSTRAINT pk_Employe_noEmp PRIMARY KEY (noEmp) 
);

It tells me that :

https://i.stack.imgur.com/2QhgX.png

And when I enter those lines on Windows, it works without warning and I can see them in the SHOW CREATE TABLE. On Mac, it doesn't show me the CONSTRAINT of this Primary key on SHOW CREATE TABLE.

I updated, downgraded, but still no solution.

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
Faisal Hotak
  • 425
  • 1
  • 5
  • 10
  • 2
    PK constraint always have a name `PRIMARY`. Without exclusions, alternatives and aliases. [CREATE TABLE](https://mariadb.com/kb/en/create-table/#index-definitions): *For PRIMARY KEY indexes, you can specify a name for the index, but it is silently ignored, and the name of the index is always PRIMARY.* – Akina Jan 17 '20 at 17:45
  • @Akina What do you mean by "have a name PRIMARY" ? – Faisal Hotak Jan 17 '20 at 17:47
  • 1
    @CloudData All indexes and constraints have a name. Most of them allow you to specify the name when you're creating them, but the primary key is always named `PRIMARY`. You're trying to give it the name `pk_Employe_noEmp`, but it can only have one name. – Barmar Jan 17 '20 at 18:16
  • Are you running the same version of MariaDB on both Windows and Mac? Maybe this restriction has changed between versions. – Barmar Jan 17 '20 at 18:17
  • Please read the article by the link. It's documentation words, I only reproduce them. – Akina Jan 17 '20 at 18:32
  • @Akina Thanks for your help ! I do have 2 different versions on Mac and Windows, and as Barmar said, the restriction has changed between versions. From 10.4.6 to 10.4.11 somewhere. – Faisal Hotak Jan 18 '20 at 12:17

1 Answers1

7

As @Akina mentioned, for PRIMARY KEY indexes, you can specify a name for the index, but it will be silently ignored, its name will always be PRIMARY.

And my problem was that I had 2 different versions (10.4.6) on windows and (10.4.11) on mac.

So basically, the 10.4.6 version of MariaDB didn’t show any warnings and they changed that in 10.4.11, by putting this warning.

Faisal Hotak
  • 425
  • 1
  • 5
  • 10