一些外键不起作用

时间:2017-10-07 11:08:07

标签: mysql sql phpmyadmin

我正在尝试使用关系船创建数据库。所以使用PHPMYADMIN,我只使用概念模式来表达我的关系。所以我看到我的不同表是链接的。但是当我导出我的数据库时,我发现除了两个或三个之外,关系就被打破了。我不知道为什么。我尝试使用sql代码,但它是一样的。

工作的关系: after export

我想要的: before export。 在这张照片中,它是我想要的所有关系。 但如果我这样做了代码

ALTER TABLE `personnel`
      ADD CONSTRAINT `personnel_ibfk_1` FOREIGN KEY (`idDroit`) REFERENCES `droit` (`id`);  

我没有错误,但在概念模式下,表之间没有链接。

这里是我的sql代码:(这是一张法语表,对不起......)

-- phpMyAdmin SQL Dump
-- version 4.1.14
-- http://www.phpmyadmin.net
--
-- Client :  127.0.0.1
-- Généré le :  Sam 07 Octobre 2017 à 10:14
-- Version du serveur :  5.6.17
-- Version de PHP :  5.5.12

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Base de données :  `projdb`
--

-- --------------------------------------------------------

--
-- Structure de la table `camps`
--

CREATE TABLE IF NOT EXISTS `camps` (
  `idinfrastructure` int(11) NOT NULL,
  `capacite` int(11) NOT NULL,
  UNIQUE KEY `idinfrastructure` (`idinfrastructure`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Structure de la table `centrale`
--

CREATE TABLE IF NOT EXISTS `centrale` (
  `idinfrastructure` int(11) NOT NULL,
  UNIQUE KEY `idinfrastructure` (`idinfrastructure`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Structure de la table `commande`
--

CREATE TABLE IF NOT EXISTS `commande` (
  `id` int(11) NOT NULL,
  `idCentrale` int(11) NOT NULL,
  `date` datetime NOT NULL,
  `etat` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Structure de la table `commande_produit`
--

CREATE TABLE IF NOT EXISTS `commande_produit` (
  `idCommande` int(11) NOT NULL,
  `idProduit` int(11) NOT NULL,
  `quantite` int(11) NOT NULL,
  KEY `idCommande` (`idCommande`),
  KEY `idProduit` (`idProduit`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Structure de la table `droit`
--

CREATE TABLE IF NOT EXISTS `droit` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `niveauPrivillege` int(11) NOT NULL,
  `nom` varchar(50) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `niveauPrivillege` (`niveauPrivillege`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Structure de la table `infrastructure`
--

CREATE TABLE IF NOT EXISTS `infrastructure` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `nom` varchar(100) NOT NULL,
  `latitude` varchar(100) NOT NULL,
  `longitude` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Structure de la table `personnel`
--

CREATE TABLE IF NOT EXISTS `personnel` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `idDroit` int(11) NOT NULL,
  `nom` varchar(50) NOT NULL,
  `prenom` varchar(50) NOT NULL,
  `date_nais` date NOT NULL,
  `adresse` varchar(300) NOT NULL,
  `telephone` varchar(35) CHARACTER SET utf32 NOT NULL,
  `mail` varchar(50) NOT NULL,
  `nationalite` int(11) NOT NULL,
  `pwd` text NOT NULL,
  PRIMARY KEY (`id`),
  KEY `idDroit` (`idDroit`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Structure de la table `produit`
--

CREATE TABLE IF NOT EXISTS `produit` (
  `id` int(11) NOT NULL,
  `nom_Produit` varchar(100) NOT NULL,
  `prix` float NOT NULL,
  `description` varchar(200) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Structure de la table `refugie`
--

CREATE TABLE IF NOT EXISTS `refugie` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `nom` varchar(50) NOT NULL,
  `prenom` varchar(50) NOT NULL,
  `date_nais` date NOT NULL,
  `grpe_sanguin` varchar(10) NOT NULL,
  `photo` varchar(150) NOT NULL,
  `nationalite` varchar(20) NOT NULL,
  `retrouve` tinyint(1) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Structure de la table `sejour`
--

CREATE TABLE IF NOT EXISTS `sejour` (
  `idRefugie` int(11) NOT NULL,
  `idCamps` int(11) NOT NULL,
  `date_arr` datetime NOT NULL,
  `date_dep` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Structure de la table `stock`
--

CREATE TABLE IF NOT EXISTS `stock` (
  `idProduit` int(11) NOT NULL,
  `idInfrastructure` int(11) NOT NULL,
  `quantite` int(11) NOT NULL,
  KEY `idInfrastructure` (`idInfrastructure`),
  KEY `idProduit` (`idProduit`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Structure de la table `travaille`
--

CREATE TABLE IF NOT EXISTS `travaille` (
  `idPersonnel` int(11) NOT NULL,
  `idInfrastructure` int(11) NOT NULL,
  `date_arr` datetime NOT NULL,
  `date_dep` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Contraintes pour les tables exportées
--

--
-- Contraintes pour la table `commande_produit`
--
ALTER TABLE `commande_produit`
  ADD CONSTRAINT `commande_produit_ibfk_2` FOREIGN KEY (`idProduit`) REFERENCES `produit` (`id`),
  ADD CONSTRAINT `commande_produit_ibfk_1` FOREIGN KEY (`idCommande`) REFERENCES `commande` (`id`);

--
-- Contraintes pour la table `stock`
--
ALTER TABLE `stock`
  ADD CONSTRAINT `stock_ibfk_1` FOREIGN KEY (`idProduit`) REFERENCES `produit` (`id`);


--
-- Contraintes pour la table `personnel`
--
ALTER TABLE `personnel`
  ADD CONSTRAINT `personnel_ibfk_1` FOREIGN KEY (`idDroit`) REFERENCES `droit` (`id`);  
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

感谢您的帮助。 托马斯

0 个答案:

没有答案
相关问题