我正在使用Hibernate在mySql数据库中创建表。 我有两张桌子" conge"和"员工"我有很多关系。 " conge" table有一个雇员id的外键。
我注意到在我的表格中插入了两行" conge"我遇到了外键问题。我已经使用了hibernate和phpmyadmin来插入,插入两行后我总是遇到同样的问题。
这是我的错误
无法添加或更新子行:外键约束失败(concretepage
。Conge
,CONSTRAINT FKk1p9i6bbic92cgaad05k4smsg
FOREIGN KEY(id
)参考EMPLOYE
(id
))
谢谢,
更新 我已导出数据库,这是sql文件
-- phpMyAdmin SQL Dump
-- version 4.7.0
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Jul 06, 2017 at 11:50 AM
-- Server version: 10.1.24-MariaDB
-- PHP Version: 7.1.6
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
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 utf8mb4 */;
--
-- Database: `concretepage`
--
-- --------------------------------------------------------
--
-- Table structure for table `Conge`
--
CREATE TABLE `Conge` (
`id` int(11) NOT NULL,
`date` datetime DEFAULT CURRENT_TIMESTAMP,
`dateDebut` date DEFAULT NULL,
`dateFin` date DEFAULT NULL,
`numero` int(11) NOT NULL,
`status` varchar(255) DEFAULT NULL,
`employe_id` int(11) DEFAULT NULL,
`typeConge_id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `Conge`
--
INSERT INTO `Conge` (`id`, `date`, `dateDebut`, `dateFin`, `numero`, `status`, `employe_id`, `typeConge_id`) VALUES
(1, '2017-07-06 10:46:30', NULL, NULL, 0, NULL, NULL, NULL),
(2, '2017-07-06 10:46:34', NULL, NULL, 0, NULL, NULL, NULL);
-- --------------------------------------------------------
--
-- Table structure for table `EMPLOYE`
--
CREATE TABLE `EMPLOYE` (
`id` int(11) NOT NULL,
`nom` varchar(255) DEFAULT NULL,
`post_id` int(11) DEFAULT NULL,
`userInfo_login` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `EMPLOYE`
--
INSERT INTO `EMPLOYE` (`id`, `nom`, `post_id`, `userInfo_login`) VALUES
(1, 'foulen', NULL, 'user'),
(2, 'falten', NULL, 'user');
-- --------------------------------------------------------
--
-- Table structure for table `POST`
--
CREATE TABLE `POST` (
`id` int(11) NOT NULL,
`code` varchar(255) DEFAULT NULL,
`intituler` varchar(255) DEFAULT NULL,
`employe_id` int(11) DEFAULT NULL,
`id_superieur` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `TypeConge`
--
CREATE TABLE `TypeConge` (
`id` int(11) NOT NULL,
`code` int(11) NOT NULL,
`intituler` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `TypeConge`
--
INSERT INTO `TypeConge` (`id`, `code`, `intituler`) VALUES
(1, 5757, 'Annuel'),
(2, 2, 'Maladie');
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE `users` (
`login` varchar(255) NOT NULL,
`country` varchar(255) DEFAULT NULL,
`enabled` smallint(6) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`role` varchar(255) DEFAULT NULL,
`employe_id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `users`
--
INSERT INTO `users` (`login`, `country`, `enabled`, `password`, `role`, `employe_id`) VALUES
('admin', NULL, 1, '$2a$10$OlJFlkoM9/nCAK1DUhcE7OvitoDHDip8GuoDt5NrSqWgV5aP7tMeC', 'ROLE_ADMIN', NULL),
('user', NULL, 1, '$2a$10$OlJFlkoM9/nCAK1DUhcE7OvitoDHDip8GuoDt5NrSqWgV5aP7tMeC', 'ROLE_USER', 1);
--
-- Indexes for dumped tables
--
--
-- Indexes for table `Conge`
--
ALTER TABLE `Conge`
ADD PRIMARY KEY (`id`),
ADD KEY `FKov9s99mmo220hv4d8ppeobut` (`employe_id`),
ADD KEY `FKocvumeoahniu5uvsjlwq5mvnp` (`typeConge_id`);
--
-- Indexes for table `EMPLOYE`
--
ALTER TABLE `EMPLOYE`
ADD PRIMARY KEY (`id`),
ADD KEY `FKpe9llqbqsni2xqg1vms2h716j` (`post_id`),
ADD KEY `FKioxxmg7s2j18x2fo7ahnclmcd` (`userInfo_login`);
--
-- Indexes for table `POST`
--
ALTER TABLE `POST`
ADD PRIMARY KEY (`id`),
ADD KEY `FKl6st4h0ujkdiun27r7tak7t7n` (`employe_id`),
ADD KEY `FK3x5ro8omrg46k9jaihue19o8q` (`id_superieur`);
--
-- Indexes for table `TypeConge`
--
ALTER TABLE `TypeConge`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`login`),
ADD KEY `FK82xfucsr861ymb3t5sp2hulo3` (`employe_id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `Conge`
--
ALTER TABLE `Conge`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
--
-- AUTO_INCREMENT for table `EMPLOYE`
--
ALTER TABLE `EMPLOYE`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
--
-- AUTO_INCREMENT for table `POST`
--
ALTER TABLE `POST`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `TypeConge`
--
ALTER TABLE `TypeConge`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
--
-- Constraints for dumped tables
--
--
-- Constraints for table `Conge`
--
ALTER TABLE `Conge`
ADD CONSTRAINT `FKk1p9i6bbic92cgaad05k4smsg` FOREIGN KEY (`id`) REFERENCES `EMPLOYE` (`id`),
ADD CONSTRAINT `FKlm34pn7fv5rcolnjgjyjnuj9l` FOREIGN KEY (`id`) REFERENCES `TypeConge` (`id`),
ADD CONSTRAINT `FKocvumeoahniu5uvsjlwq5mvnp` FOREIGN KEY (`typeConge_id`) REFERENCES `TypeConge` (`id`),
ADD CONSTRAINT `FKov9s99mmo220hv4d8ppeobut` FOREIGN KEY (`employe_id`) REFERENCES `EMPLOYE` (`id`);
--
-- Constraints for table `EMPLOYE`
--
ALTER TABLE `EMPLOYE`
ADD CONSTRAINT `FKioxxmg7s2j18x2fo7ahnclmcd` FOREIGN KEY (`userInfo_login`) REFERENCES `users` (`login`),
ADD CONSTRAINT `FKpe9llqbqsni2xqg1vms2h716j` FOREIGN KEY (`post_id`) REFERENCES `POST` (`id`);
--
-- Constraints for table `POST`
--
ALTER TABLE `POST`
ADD CONSTRAINT `FK3x5ro8omrg46k9jaihue19o8q` FOREIGN KEY (`id_superieur`) REFERENCES `POST` (`id`),
ADD CONSTRAINT `FKl6st4h0ujkdiun27r7tak7t7n` FOREIGN KEY (`employe_id`) REFERENCES `EMPLOYE` (`id`);
--
-- Constraints for table `users`
--
ALTER TABLE `users`
ADD CONSTRAINT `FK82xfucsr861ymb3t5sp2hulo3` FOREIGN KEY (`employe_id`) REFERENCES `EMPLOYE` (`id`);
COMMIT;
/*!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 :(得分:1)
因为外键位于列ID
而不是employee_id
...看:FOREIGN KEY(id)REFERENCES EMPLOYE(id))...并且您在Employee表中只有两行< / p>