Bonjour,

Je suis en train de créer une base de donnée pour un projet de stage, la partie d'analyse étant terminée (MCD) je suis passé à la partie SQL. Ma base de données contient 5 tables mais voici le MLD c'est plus parlant

Utilisateur(id_util, login_util, passwd_util, droits_util)
Information(id_info, rang_info, titre_info, msg_info, img_info, vid_info, date_info, type_info, #id_util)
Absence(id_abs, rang_abs, msg_abs, debut_abs, fin_abs, #id_ens, #id_util)
Enseignant(id_ens, civilite_ens, nom_ens, prenom_ens, #id_mat)
Matiere(id_mat, intitule_mat)
De là j'ai écrit un script pour mysql qui me génère cette base de donnée, seulement j'ai un problème avec le lien entre la table absence et la table enseignant..

Lorsque je passe SET FOREIGN_KEY_CHECKS à 0 mon script s'exécute cependant en visualisant le schéma de la BDD dans PHPMyAdmin (avec le concepteur graphique) je vois qu'il me manque le lien entre absence et enseignant.

Lorsque je passe SET FOREIGN_KEY_CHECKS à 1 mysql me retourne deux erreurs que voici :

Error code 1005, SQL state HY000: Can't create table 'experiment.enseignant' (errno: 150)
Line 42, column 1

Error code 1005, SQL state HY000: Can't create table 'experiment.absence' (errno: 150)
Line 57, column 1
J'ai fait des recherches sur le net pour connaitre l'ititulé de cette erreur mais les réponses sont assez vague. Apparament c'est quelque chose avec NOT NULL ?

Je vais vous présenter mon script SQL, pour le réalisé j'ai utilisé mes ressources (cours) et un script autogénéré avec phpmyadmin d'une autre base de données du serveur.

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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
 
SET FOREIGN_KEY_CHECKS=1;
DROP TABLE IF EXISTS `matiere`;
DROP TABLE IF EXISTS `enseignant`;
DROP TABLE IF EXISTS `absence`;
DROP TABLE IF EXISTS `information`;
DROP TABLE IF EXISTS `utilisateur`;
 
-- -----------------------------------
-- Structure de la table `utilisateur`
-- -----------------------------------
CREATE TABLE `utilisateur` (
	`id_util` smallint(6) unsigned NOT NULL AUTO_INCREMENT,
	`login_util` varchar(15) NOT NULL,
	`passwd_util` varchar(15) NOT NULL,
	`droits_util` smallint(3) unsigned NOT NULL,
	PRIMARY KEY (`id_util`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
 
-- -------------------------------
-- Structure de la table `matiere`
-- -------------------------------
CREATE TABLE `matiere` (
	`id_mat` smallint(6) unsigned NOT NULL AUTO_INCREMENT,
	`intitule_mat` varchar(25) NOT NULL,
	PRIMARY KEY (`id_mat`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
 
-- ----------------------------------
-- Structure de la table `enseignant`
-- ----------------------------------
CREATE TABLE `enseignant` (
	`id_ens` smallint(6) unsigned NOT NULL AUTO_INCREMENT,
	`civilite_ens` varchar(4) NOT NULL,
	`nom_ens` varchar(15) NOT NULL,
	`prenom_ens` varchar(15) NOT NULL,
	`id_mat` smallint(6) unsigned NOT NULL,
	PRIMARY KEY (`id_ens`),
	KEY `id_mat` (`id_mat`),
	CONSTRAINT `matiere_ibfk_1` FOREIGN KEY (`id_mat`) REFERENCES `id_mat` (`id_mat`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
 
-- -------------------------------
-- Structure de la table `Absence`
-- -------------------------------
CREATE TABLE `absence` (
	`id_abs` smallint(6) unsigned NOT NULL AUTO_INCREMENT,
	`rang_abs` smallint(3) unsigned NOT NULL,
	`msg_abs` varchar(120) NOT NULL,
	`debut_abs` bigint(20) unsigned NOT NULL,
	`fin_abs` bigint(20) unsigned NOT NULL,
	`id_ens` smallint(6) unsigned NOT NULL,
	`id_util` smallint(6) unsigned NOT NULL,
	PRIMARY KEY (`id_abs`),
	KEY `id_ens` (`id_ens`),
	KEY `id_util` (`id_util`),
	CONSTRAINT `enseignant_ibfk_1` FOREIGN KEY (`id_ens`) REFERENCES `id_ens` (`id_ens`) ON DELETE CASCADE ON UPDATE CASCADE,
	CONSTRAINT `information_ibfk_2` FOREIGN KEY (`id_util`) REFERENCES `utilisateur` (`id_util`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
 
-- -----------------------------------
-- Structure de la table `information`
-- -----------------------------------
CREATE TABLE `information` (
	`id_info` smallint(6) unsigned NOT NULL AUTO_INCREMENT,
	`rang_info` smallint(3) unsigned NOT NULL,
	`titre_info` varchar(50) NOT NULL,
	`msg_info` text NOT NULL,
	`img_info` varchar(60) NOT NULL,
	`vid_info` varchar(60) NOT NULL,
	`date_info` bigint(20) unsigned NOT NULL,
	`type_info` smallint(3) unsigned NOT NULL,
	`id_util` smallint(6) unsigned NOT NULL,
	PRIMARY KEY (`id_info`),
	KEY `id_util` (`id_util`),
	CONSTRAINT `information_ibfk_1` FOREIGN KEY (`id_util`) REFERENCES `utilisateur` (`id_util`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Merci pour votre aide