Bonjour,
Je suis actuellement en BTS informatique et on a commencé le SQL. Je voulais créer une clé étrangère.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 describe Vehicule; +------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------+--------------+------+-----+---------+-------+ | immatriculation | varchar(10) | YES | | NULL | | | modèle | varchar(100) | YES | | NULL | | | codeTypeVehicule | varchar(5) | NO | PRI | NULL | | +------------------+--------------+------+-----+---------+-------+ describe Location; +---------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+-------+ | ID | int(11) | NO | PRI | NULL | | | dateDebut | date | YES | | NULL | | | dateFin | date | YES | | NULL | | | immatVehicule | varchar(10) | YES | | NULL | | +---------------+-------------+------+-----+---------+-------+ ALTER TABLE Location -> ADD FOREIGN KEY(immatVehicule) -> REFERENCES Vehicule(immatriculation); ERROR 1005 (HY000): Can't create table `gervaa`.`Location` (errno: 150 "Foreign key constraint is incorrectly formed") show warnings; | Warning | 150 | Alter table `gervaa`.`Location` with foreign key constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns near 'FOREIGN KEY(immatVehicule) REFERENCES Vehicule(immatriculation)'. | | Error | 1005 | Can't create table `gervaa`.`Location` (errno: 150 "Foreign key constraint is incorrectly formed") | | Warning | 1215 | Cannot add foreign key constraint for `Location`
Et j'ai ce message d'erreur, j'ai cherché un peu partout mais j'ai pas trouvé.
Merci à ceux qui m'aideront !
Partager