Création de tables et FOREIGN KEY
Bonjour,
Je cherche, via python, à créer des tables mariaDB dont l'une doit contenir des clés provenant des 2 autres:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
# Table 1
t_1 = """
CREATE TABLE IF NOT EXISTS t_1 (
ID INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
ID_T_2 INT UNSIGNED NOT NULL,
ID_T_3 INT UNSIGNED NOT NULL,
.../...
FOREIGN KEY (ID_T_2) REFERENCES nom_database.t_2(id_t2),
FOREIGN KEY (ID_T_3) REFERENCES nom_database.t_3(id_t3)
);"""
# Table2
t_2 = """
CREATE TABLE IF NOT EXISTS t_2 (
id_t2 INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
.../...
);"""
# Table3
t_3 = """
CREATE TABLE IF NOT EXISTS t_3(
id_t3 INT UNSIGNED NOT NULL PRIMARY KEY AUTO INCREMENT,
.../...
);""" |
Mais j'obtiens une erreur:
Code:
Can't create table `db_solardata`.`t_Solar_Data` (errno: 150 "Foreign key constraint is incorrectly formed")
Quelle est la bonne syntaxe ? Je cherche ne trouve pas mon erreur.
Merci de votre aide.