MySQL #1100 - Table 'USER' was not locked with LOCK TABLES - mysql

I am having a very strange problem. I have developed a database and it works perfectly on my local server however then I tried to put it online on my server I keep getting MySQL error:
#1100 - Table 'USER' was not locked with LOCK TABLES
(This is then I try to import my .sql file via phpMyAdmin)
Once again this same script gives no errors on my local server (WAMP server)
I have no Idea why it does not work then I try to put it online. Also it creates the tables and structure the problem is only with the insert statements.
SQL script:
/*!40101 SET NAMES utf8 */;
/*!40101 SET SQL_MODE=''*/;
/*!40014 SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`a3823833_MiniPos` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `a3823833_MiniPos`;
/*Table structure for table `user` */
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`userid` int(4) NOT NULL auto_increment,
`username` varchar(20) NOT NULL,
`password` varchar(20) NOT NULL,
`email` varchar(50) NOT NULL,
PRIMARY KEY (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*Table structure for table `profile` */
DROP TABLE IF EXISTS `profile`;
CREATE TABLE `profile` (
`userid` int(4) NOT NULL,
`lastName` varchar(50),
`firstName` varchar(50),
`dob` varchar(10),
PRIMARY KEY (`userid`),
CONSTRAINT `profile_fk` FOREIGN KEY (`userid`) REFERENCES `user` (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*Table structure for table 'topic'*/
DROP TABLE IF EXISTS `topic`;
CREATE TABLE `topic` (
`topicid` int(4) NOT NULL auto_increment,
`userid` int(4) NOT NULL,
`text` varchar(2000),
`time` datetime,
PRIMARY KEY (`topicid`),
CONSTRAINT `userid_fk` FOREIGN KEY (`userid`) REFERENCES `user` (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/* Table structure for table 'post'*/
DROP TABLE IF EXISTS `post`;
CREATE TABLE `post` (
`postid` int(4) NOT NULL auto_increment,
`topicid` int(4),
`userid` int(4) NOT NULL,
`text` varchar(2000),
`time` datetime,
PRIMARY KEY (`postid`),
CONSTRAINT `post_userid_fk` FOREIGN KEY (`userid`) REFERENCES `user` (`userid`),
CONSTRAINT `post_topicid_fk` FOREIGN KEY (`topicid`) REFERENCES `topic` (`topicid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
LOCK TABLES `user` WRITE;
INSERT INTO USER VALUES (1,'Martynas','MartynPass','Martyn#email.com'),(2,'Syed','SyedPass','Syed#email.com'),(3,'Stephanie','StephPass','Steph#email.com');
UNLOCK TABLES;
LOCK TABLES `topic` WRITE;
INSERT INTO topic VALUES (1, 1,'Topic Number 1','2015-06-11 20:15:00'),(2, 2,'Topic Number 2','2015-06-10 19:15:00'),(3, 3,'Topic Number 3','2015-06-09 18:15:00');
UNLOCK TABLES;
LOCK TABLES `post` WRITE;
INSERT INTO post VALUES (1, 1, 1, 'Very Interesting Topic Number 1','2015-06-11 20:15:00'),(2, 1, 2, 'Agree!','2015-06-11 21:15:00');
UNLOCK TABLES;

Related

Does anyone know how to fix Error 1103 in MySQL?

I am quite new to MySQL, I downloaded the file and then opened it in SQL I ran it, but it didn't work and stated the following
Error Code: 1103. Incorrect table name 'campaign';/!40101 SET #saved_cs_client = ##character_set_client /;/!40101 SET character_set'
This is where I believe the problem is
DROP TABLE IF EXISTS `campaign';
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `campaign` (
`id` bigint(20) NOT NULL,
`name` text,
`sub_category_id` bigint(20) DEFAULT NULL,
`country_id` bigint(20) DEFAULT NULL,
`currency_id` bigint(20) DEFAULT NULL,
`launched` datetime DEFAULT NULL,
`deadline` datetime DEFAULT NULL,
`goal` double DEFAULT NULL,
`pledged` double DEFAULT NULL,
`backers` bigint(20) DEFAULT NULL,
`outcome` text,
PRIMARY KEY (`id`),
KEY `country_id` (`country_id`),
KEY `sub_category_id` (`sub_category_id`),
KEY `currency_id` (`currency_id`),
CONSTRAINT `campaign_ibfk_1` FOREIGN KEY (`country_id`) REFERENCES `country` (`id`),
CONSTRAINT `campaign_ibfk_2` FOREIGN KEY (`sub_category_id`) REFERENCES `sub_category` (`id`),
CONSTRAINT `campaign_ibfk_3` FOREIGN KEY (`currency_id`) REFERENCES `currency` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
Dumping data for table `campaign`
--
LOCK TABLES `campaign` WRITE;
/*!40000 ALTER TABLE `campaign` DISABLE KEYS */;
INSERT INTO `campaign` VALUES (1,'Ragdolls',23,2,2)
INSERT INTO `campaign` VALUES (8667,'Blank Screen Films Summer Project 2013')
/*!40000 ALTER TABLE `campaign` ENABLE KEYS */;
UNLOCK TABLES;
Feel free to ask any question to attain more insight.
Where you have:
DROP TABLE IF EXISTS `campaign';
this is supposed to be:
DROP TABLE IF EXISTS `campaign`;
Either you accidentally changed the backtick to a single quote, or something in your "downloaded the file and then opened it in SQL" changed it on you.

SQL query is executed on web hosting with error but on localhost it runs without a problem

I want to upload my project online. Recently I've bought web hosting service and I've already checked the version of my and their server - 10.1.38-MariaDB. The following query runs without a problem on my localhost database server, but when I tried to run it online I'm getting the following error, why?
1005 - Can't create table psyclade_project.companies (errno: 150 "Foreign key constraint is incorrectly formed")
Obviously the problem is the foreign keys, how could I fix it?
The query is:
-- --------------------------------------------------------
-- Host: 127.0.0.1
-- Server version: 10.1.38-MariaDB - mariadb.org binary distribution
-- Server OS: Win64
-- HeidiSQL Version: 10.2.0.5607
-- --------------------------------------------------------
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40014 SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
-- Dumping structure for table dev.companies
CREATE TABLE IF NOT EXISTS `companies` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`owner_id` int(11) DEFAULT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UNIQ_8244AA3A5E237E06` (`name`),
UNIQUE KEY `UNIQ_8244AA3A7E3C61F9` (`owner_id`),
CONSTRAINT `FK_8244AA3A7E3C61F9` FOREIGN KEY (`owner_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- Data exporting was unselected.
-- Dumping structure for table dev.jobs
CREATE TABLE IF NOT EXISTS `jobs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`author_id` int(11) DEFAULT NULL,
`title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`content` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`createdOn` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `IDX_A8936DC5F675F31B` (`author_id`),
CONSTRAINT `FK_A8936DC5F675F31B` FOREIGN KEY (`author_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- Data exporting was unselected.
-- Dumping structure for table dev.roles
CREATE TABLE IF NOT EXISTS `roles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UNIQ_B63E2EC75E237E06` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- Data exporting was unselected.
-- Dumping structure for table dev.schools
CREATE TABLE IF NOT EXISTS `schools` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UNIQ_47443BD55E237E06` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- Data exporting was unselected.
-- Dumping structure for table dev.users
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`school_id` int(11) DEFAULT NULL,
`username` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`full_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`ages` int(10) unsigned DEFAULT NULL,
`password` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UNIQ_1483A5E9F85E0677` (`username`),
UNIQUE KEY `UNIQ_1483A5E9E7927C74` (`email`),
KEY `IDX_1483A5E9C32A47EE` (`school_id`),
CONSTRAINT `FK_1483A5E9C32A47EE` FOREIGN KEY (`school_id`) REFERENCES `schools` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- Data exporting was unselected.
-- Dumping structure for table dev.users_roles
CREATE TABLE IF NOT EXISTS `users_roles` (
`user_id` int(11) NOT NULL,
`role_id` int(11) NOT NULL,
PRIMARY KEY (`user_id`,`role_id`),
KEY `IDX_51498A8EA76ED395` (`user_id`),
KEY `IDX_51498A8ED60322AC` (`role_id`),
CONSTRAINT `FK_51498A8EA76ED395` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),
CONSTRAINT `FK_51498A8ED60322AC` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- Data exporting was unselected.
/*!40101 SET SQL_MODE=IFNULL(#OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IF(#OLD_FOREIGN_KEY_CHECKS IS NULL, 1, #OLD_FOREIGN_KEY_CHECKS) */;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
If you want to execute this dump using the SQL tab in phpMyAdmin, you have to uncheck the "Enable foreign key checks" box, which you will find near the "Go" button.

Creating MYSQL table with foreign key ERROR

CREATE TABLE `u914452720_yzawa`.`aucs_manufacturer_files`
( `id` INT NOT NULL AUTO_INCREMENT , `manufacturer_id` INT NOT NULL,
FOREIGN KEY ('manufacturer_id') REFERENCES aucs_manufacturer(manufacturer_id) ON DELETE CASCADE)
ENGINE=INNODB;
got error:
SQL query:
CREATE TABLE `u914452720_yzawa`.`aucs_manufacturer_files`
( `id` INT NOT NULL AUTO_INCREMENT , `manufacturer_id` INT NOT NULL,
FOREIGN KEY ('manufacturer_id') REFERENCES aucs_manufacturer(manufacturer_id) ON DELETE CASCADE)
ENGINE=INNODB
MySQL atsakymas: Dokumentacija
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''manufacturer_id') REFERENCES aucs_manufacturer(manufacturer_id) ON DELETE CASCA' at line 3
EXPORTED TABLE FROM WHICH I WANT TO GET MANUFACTURER_ID:
-- phpMyAdmin SQL Dump
-- version 4.9.2
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1:3306
-- Generation Time: 2019 m. Grd 16 d. 11:37
-- Server version: 10.2.27-MariaDB
-- PHP Version: 7.2.23
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: `u914452720_yzawa`
--
-- --------------------------------------------------------
--
-- Sukurta duomenų struktūra lentelei `aucs_manufacturer`
--
CREATE TABLE `aucs_manufacturer` (
`manufacturer_id` int(11) NOT NULL,
`name` varchar(64) NOT NULL,
`image` varchar(255) DEFAULT NULL,
`instruction` varchar(255) DEFAULT NULL,
`catalog` varchar(255) DEFAULT NULL,
`sketch` varchar(255) DEFAULT NULL,
`sort_order` int(3) NOT NULL,
`id` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `aucs_manufacturer`
--
ALTER TABLE `aucs_manufacturer`
ADD PRIMARY KEY (`manufacturer_id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `aucs_manufacturer`
--
ALTER TABLE `aucs_manufacturer`
MODIFY `manufacturer_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=31;
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 */;
Probably the single quotes might not be necessary and both the referenced table and the new table that is being created have to be on the same Engine (MyISAM in this case).
CREATE TABLE `aucs_manufacturer_files`
( `id` INT PRIMARY KEY AUTO_INCREMENT , `manufacturer_id` INT NOT NULL,
FOREIGN KEY (manufacturer_id) REFERENCES aucs_manufacturer(manufacturer_id) ON DELETE CASCADE)
ENGINE=MyISAM DEFAULT CHARSET=utf8;
Without knowing a lot about the other table that you are trying to reference, it's hard for us to guess certain information. I put together this SQLFiddle to demonstrate a working solution.
create table am (
id int unique not null auto_increment
)
ENGINE=INNODB;
CREATE TABLE amf
( `id` INT unique NOT NULL AUTO_INCREMENT , `manufacturer_id` INT NOT NULL,
FOREIGN KEY (manufacturer_id) REFERENCES am(id) ON DELETE CASCADE)
ENGINE=INNODB;
insert into am(id) values (null),(null),(null),(null),(null),(null),(null);
insert into amf(id, manufacturer_id) VALUES (null, 1),(null, 2),(null, 3),(null, 2),(null, 1),(null, 4),(null, 6);
delete from am where id = 6;
If you run the SELECT * from amf you will see that there are no values with the manufacturer_id as 6, meaning that the cascade worked correctly.
try this, hope this would work:
CREATE TABLE `u914452720_yzawa`.`aucs_manufacturer_files`
( `id` INT NOT NULL AUTO_INCREMENT , `manufacturer_id` INT,
FOREIGN KEY (manufacturer_id) REFERENCES aucs_manufacturer(manufacturer_id) ON DELETE CASCADE)
ENGINE=INNODB
After you fixed the single quotes that should have been backticks or removed altogether, you have:
CREATE TABLE `u914452720_yzawa`.`aucs_manufacturer_files` (
`id` INT NOT NULL AUTO_INCREMENT ,
`manufacturer_id` INT NOT NULL,
FOREIGN KEY ('manufacturer_id') REFERENCES aucs_manufacturer(manufacturer_id) ON DELETE CASCADE
) ENGINE=INNODB;
And you are getting this error:
#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
This has nothing to do with the foreign key; it results from specifying auto increment for a column that is not a key. Presumably you meant to say:
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
(If you end up with yet another error after fixing this, please make sure to edit your question with the new create statement, error message, and output from show create table aucs_manufacturer.)

foreign key and mysql with hibernate

I am using Hibernate to create table in mySql database.
I have two table "conge" and "employee" and I have a manytoone relationship. the "conge" table have a foreign key of the employee id.
I notice that after inserting exactly two row in my table "conge" I get a foreign key problem. I have used hibernate and also the phpmyadmin to insert and I have always the same problem after inserting two row.
this is my error
Cannot add or update a child row: a foreign key constraint fails (concretepage.Conge, CONSTRAINT FKk1p9i6bbic92cgaad05k4smsg FOREIGN KEY (id) REFERENCES EMPLOYE (id))
Thanks,
Update
I have exported the database this is the sql file
-- 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 */;
Because the foreign key is on column ID not employee_id ... look : FOREIGN KEY (id) REFERENCES EMPLOYE (id)) ... and you have only two rows in Employee table

Cannot Create Table after Lowercased all text in MySQL Dump file

I'm having an error restoring tables which have Foreign Keys after lowercasing the contents of a mysql dump file.
My goal is to lowercase all structure in a mysql database.
I used vim to lowercase all contents of a mysqldump file when trying to restore the database, this is the error I get.
$ mysql -u [user] -p[password] dme < mysqldump.sql
ERROR 1005 (HY000) at line 399: Can't create table 'dme.contacts' (errno: 121)
The restore is error'ing out on any table which has Foreign Key contstraints. If I remove lines after the Primary Key for each table, the entire restore works fine.
My question is, what is causing this and how can I keep my Foreign Keys in the process?
Lowercased.sql example which results in the error (fyi prior to dme.contacts there are multiple tables which are created just fine. Only tables w/ Foreign Keys and Contstraints have issues.)
drop table if exists `contacts`;
/*!40101 set #saved_cs_client = ##character_set_client */;
/*!40101 set character_set_client = utf8 */;
create table `contacts` (
`contactid` int(11) not null auto_increment,
`firstname` varchar(100) default null,
`lastname` varchar(100) not null,
`fullname` varchar(200) not null,
`dob` datetime default null,
`sex` char(1) default null,
`voided` datetime default null,
`vendorid` int(11) not null,
`contacttypeid` int(11) default null,
`comments` varchar(1500) default null,
primary key (`contactid`),
key `fk_contacts_vendors` (`vendorid`),
key `fk_contacts_contacttype` (`contacttypeid`),
constraint `fk_contacts_contacttype` foreign key (`contacttypeid`) references `contacttype` (`contacttypeid`) on delete no action on update no action,
constraint `fk_contacts_vendors` foreign key (`vendorid`) references `vendors` (`vendorid`) on delete no action on update no action
) engine=innodb default charset=utf8;
/*!40101 set character_set_client = #saved_cs_client */;
--
-- dumping data for table `contacts`
--
lock tables `contacts` write;
/*!40000 alter table `contacts` disable keys */;
/*!40000 alter table `contacts` enable keys */;
unlock tables;
Original from the mysqldump.sql (No Error)
--
-- Table structure for table `Contacts`
--
DROP TABLE IF EXISTS `Contacts`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `Contacts` (
`ContactId` int(11) NOT NULL AUTO_INCREMENT,
`FirstName` varchar(100) DEFAULT NULL,
`LastName` varchar(100) NOT NULL,
`FullName` varchar(200) NOT NULL,
`DOB` datetime DEFAULT NULL,
`Sex` char(1) DEFAULT NULL,
`Voided` datetime DEFAULT NULL,
`VendorID` int(11) NOT NULL,
`ContactTypeID` int(11) DEFAULT NULL,
`Comments` varchar(1500) DEFAULT NULL,
PRIMARY KEY (`ContactId`),
KEY `FK_Contacts_Vendors` (`VendorID`),
KEY `FK_Contacts_ContactType` (`ContactTypeID`),
CONSTRAINT `FK_Contacts_ContactType` FOREIGN KEY (`ContactTypeID`) REFERENCES `ContactType` (`ContactTYpeID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `FK_Contacts_Vendors` FOREIGN KEY (`VendorID`) REFERENCES `Vendors` (`VendorId`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `Contacts`
--
LOCK TABLES `Contacts` WRITE;
/*!40000 ALTER TABLE `Contacts` DISABLE KEYS */;
/*!40000 ALTER TABLE `Contacts` ENABLE KEYS */;
UNLOCK TABLES;
Try removing the constrain name. Sample:
constraint `fk_contacts_contacttype` foreign key (`contacttypeid`) ....
To
constraint foreign key (`contacttypeid`) ...