Cannot Create Table after Lowercased all text in MySQL Dump file - mysql

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`) ...

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.

Problem with importing mysql workbench data

I have a table and data. When importing, automatically importing data into the user table throws a foreign key error. How do I load data into a table?
I understand that the problem is in the foreign key and the difference in id and name, but how to import the data?
need to write some kind of request?
This is the csv of the loaded data
Administrator,j.doe#amonic.com,123,John,Doe,Abu dhabi,1/13/1983,1
User,k.omar#amonic.com,4258,Karim,Omar,Abu dhabi,3/19/1980,1
User,h.saeed#amonic.com,2020,Hannan,Saeed,Cairo,12/20/1989,1
User,a.hobart#amonic.com,6996,Andrew,Hobart,Riyadh,1/30/1990,1
User,k.anderson#amonic.com,4570,Katrin,Anderson,Doha,11/10/1992,1
User,h.wyrick#amonic.com,1199,Hava,Wyrick,Abu dhabi,8/8/1988,1
User,marie.horn#amonic.com,55555,Marie,Horn,Bahrain,4/6/1981,1
User,m.osteen#amonic.com,9800,Milagros,Osteen,Abu dhabi,2/3/1991,0
and this is the mysql code
-- Dumping data for table `countries`
--
LOCK TABLES `countries` WRITE;
/*!40000 ALTER TABLE `countries` DISABLE KEYS */;
INSERT INTO `countries` VALUES (1,'Afghanistan'),(2,'Albania'),(3,'Algeria'),(4,'Andorra'),(5,'Angola'),(6,'Antigua & Deps'),(7,'Argentina'),(8,'Armenia'),(9,'Australia'),(10,'Austria'),(11,'Azerbaijan'),(12,'Bahamas'),(13,'Bahrain'),(14,'Bangladesh'),(15,'Barbados'),(16,'Belarus'),(17,'Belgium'),(18,'Belize'),(19,'Benin'),(20,'Bhutan'),(21,'Bolivia'),(22,'Bosnia Herzegovina'),(23,'Botswana'),(24,'Brazil'),(25,'Brunei'),(26,'Bulgaria'),(27,'Burkina'),(28,'Burundi'),(29,'Cambodia'),(30,'Cameroon'),(31,'Canada'),(32,'Cape Verde'),(33,'Central African Rep'),(34,'Chad'),(35,'Chile'),(36,'China'),(37,'Colombia'),(38,'Comoros'),(39,'Congo'),(40,'Congo {Democratic Rep}'),(41,'Costa Rica'),(42,'Croatia'),(43,'Cuba'),(44,'Cyprus'),(45,'Czech Republic'),(46,'Denmark'),(47,'Djibouti'),(48,'Dominica'),(49,'Dominican Republic'),(50,'East Timor'),(51,'Ecuador'),(52,'Egypt'),(53,'El Salvador'),(54,'Equatorial Guinea'),(55,'Eritrea'),(56,'Estonia'),(57,'Ethiopia'),(58,'Fiji'),(59,'Finland'),(60,'France'),(61,'Gabon'),(62,'Gambia'),(63,'Georgia'),(64,'Germany'),(65,'Ghana'),(66,'Greece'),(67,'Grenada'),(68,'Guatemala'),(69,'Guinea'),(70,'Guinea-Bissau'),(71,'Guyana'),(72,'Haiti'),(73,'Honduras'),(74,'Hungary'),(75,'Iceland'),(76,'India'),(77,'Indonesia'),(78,'Iran'),(79,'Iraq'),(80,'Ireland {Republic}'),(81,'Israel'),(82,'Italy'),(83,'Ivory Coast'),(84,'Jamaica'),(85,'Japan'),(86,'Jordan'),(87,'Kazakhstan'),(88,'Kenya'),(89,'Kiribati'),(90,'Korea North'),(91,'Korea South'),(92,'Kosovo'),(93,'Kuwait'),(94,'Kyrgyzstan'),(95,'Laos'),(96,'Latvia'),(97,'Lebanon'),(98,'Lesotho'),(99,'Liberia'),(100,'Libya'),(101,'Liechtenstein'),(102,'Lithuania'),(103,'Luxembourg'),(104,'Macedonia'),(105,'Madagascar'),(106,'Malawi'),(107,'Malaysia'),(108,'Maldives'),(109,'Mali'),(110,'Malta'),(111,'Marshall Islands'),(112,'Mauritania'),(113,'Mauritius'),(114,'Mexico'),(115,'Micronesia'),(116,'Moldova'),(117,'Monaco'),(118,'Mongolia'),(119,'Montenegro'),(120,'Morocco'),(121,'Mozambique'),(122,'Myanmar, {Burma}'),(123,'Namibia'),(124,'Nauru'),(125,'Nepal'),(126,'Netherlands'),(127,'New Zealand'),(128,'Nicaragua'),(129,'Niger'),(130,'Nigeria'),(131,'Norway'),(132,'Oman'),(133,'Pakistan'),(134,'Palau'),(135,'Panama'),(136,'Papua New Guinea'),(137,'Paraguay'),(138,'Peru'),(139,'Philippines'),(140,'Poland'),(141,'Portugal'),(142,'Qatar'),(143,'Romania'),(144,'Russian Federation'),(145,'Rwanda'),(146,'St Kitts & Nevis'),(147,'St Lucia'),(148,'Saint Vincent & the Grenadines'),(149,'Samoa'),(150,'San Marino'),(151,'Sao Tome & Principe'),(152,'Saudi Arabia'),(153,'Senegal'),(154,'Serbia'),(155,'Seychelles'),(156,'Sierra Leone'),(157,'Singapore'),(158,'Slovakia'),(159,'Slovenia'),(160,'Solomon Islands'),(161,'Somalia'),(162,'South Africa'),(163,'South Sudan'),(164,'Spain'),(165,'Sri Lanka'),(166,'Sudan'),(167,'Suriname'),(168,'Swaziland'),(169,'Sweden'),(170,'Switzerland'),(171,'Syria'),(172,'Taiwan'),(173,'Tajikistan'),(174,'Tanzania'),(175,'Thailand'),(176,'Togo'),(177,'Tonga'),(178,'Trinidad & Tobago'),(179,'Tunisia'),(180,'Turkey'),(181,'Turkmenistan'),(182,'Tuvalu'),(183,'Uganda'),(184,'Ukraine'),(185,'United Arab Emirates'),(186,'United Kingdom'),(187,'United States'),(188,'Uruguay'),(189,'Uzbekistan'),(190,'Vanuatu'),(191,'Vatican City'),(192,'Venezuela'),(193,'Vietnam'),(194,'Yemen'),(195,'Zambia'),(196,'Zimbabwe');
/*!40000 ALTER TABLE `countries` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `offices`
--
DROP TABLE IF EXISTS `offices`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `offices` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`CountryID` int(11) NOT NULL,
`Title` varchar(50) COLLATE utf8_bin NOT NULL,
`Phone` varchar(50) COLLATE utf8_bin NOT NULL,
`Contact` varchar(250) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`ID`),
KEY `FK_Office_Country` (`CountryID`),
CONSTRAINT `FK_Office_Country` FOREIGN KEY (`CountryID`) REFERENCES `countries` (`ID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `offices`
--
LOCK TABLES `offices` WRITE;
/*!40000 ALTER TABLE `offices` DISABLE KEYS */;
INSERT INTO `offices` VALUES (1,185,'Abu dhabi','638-757-8582\r\n','MIchael Malki'),(3,52,'Cairo','252-224-8525','David Johns'),(4,13,'Bahrain','542-227-5825','Katie Ballmer'),(5,142,'Doha','758-278-9597','Ariel Levy'),(6,152,'Riyadh','285-285-1474','Andrew Hobart');
/*!40000 ALTER TABLE `offices` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `roles`
--
DROP TABLE IF EXISTS `roles`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `roles` (
`ID` int(11) NOT NULL,
`Title` varchar(50) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `roles`
--
LOCK TABLES `roles` WRITE;
/*!40000 ALTER TABLE `roles` DISABLE KEYS */;
INSERT INTO `roles` VALUES (1,'Administrator'),(2,'User');
/*!40000 ALTER TABLE `roles` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `users`
--
DROP TABLE IF EXISTS `users`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `users` (
`ID` int(11) NOT NULL,
`RoleID` int(11) NOT NULL,
`Email` varchar(150) COLLATE utf8_bin NOT NULL,
`Password` varchar(50) COLLATE utf8_bin NOT NULL,
`FirstName` varchar(50) COLLATE utf8_bin DEFAULT NULL,
`LastName` varchar(50) COLLATE utf8_bin NOT NULL,
`OfficeID` int(11) DEFAULT NULL,
`Birthdate` date DEFAULT NULL,
`Active` tinyint(1) DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `FK_Users_Offices` (`OfficeID`),
KEY `FK_Users_Roles` (`RoleID`),
CONSTRAINT `FK_Users_Offices` FOREIGN KEY (`OfficeID`) REFERENCES `offices` (`ID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `FK_Users_Roles` FOREIGN KEY (`RoleID`) REFERENCES `roles` (`ID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `users`
--

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.

Can't find why Foreign key is incorrectly formed

Sometimes when I shut down the xampp local server some table is "in use" and I can't open it or delete it.
So I pick the last backup and drop the base, which is not possible because of the tables in use.
At Stack Overflow some said to manually delete the MySQL data in my phpmyadmin folder, ibd and frm files.
But then I tried to import my backup and it said "Foreign key is incorrectly formed".
When I go to details it shows this:
LATEST FOREIGN KEY ERROR
2019-05-15 17:09:40 1c6c Error in foreign key constraint of table
service_tunnels/se_situer_a: there is no index in the table which
would contain the columns as the first columns, or the data types in
the table do not match the ones in the referenced table or one of the
ON ... SET NULL columns is declared NOT NULL. Constraint: ,
CONSTRAINT "FK_Se_situer_a_IDEmplacement" FOREIGN KEY
("IDEmplacement") REFERENCES "emplacement" ("IDEmplacement")
Here is the sql part for table emplacement and table se_situer_a :
DROP TABLE IF EXISTS `emplacement`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `emplacement` (
`IDEmplacement` int(11) NOT NULL,
`NomEmplacement` varchar(50) COLLATE latin1_general_ci DEFAULT NULL,
`PointKilometrique` float DEFAULT NULL,
`NumLocal` int(11) NOT NULL,
`CodeOuvrage` varchar(25) COLLATE latin1_general_ci NOT NULL,
PRIMARY KEY (`IDEmplacement`,`NumLocal`,`CodeOuvrage`),
KEY `FK_Emplacement_CodeOuvrage` (`CodeOuvrage`),
CONSTRAINT `FK_Emplacement_CodeOuvrage` FOREIGN KEY (`CodeOuvrage`) REFERENCES `ouvrage` (`CodeOuvrage`),
CONSTRAINT `FK_Emplacement_NumLocal` FOREIGN KEY (`NumLocal`) REFERENCES `local` (`NumLocal`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
/*!40101 SET character_set_client = #saved_cs_client */;
DROP TABLE IF EXISTS `se_situer_a`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `se_situer_a` (
`DateMiseEnPlace` date DEFAULT NULL,
`DateEnlevement` date DEFAULT NULL,
`IDEquipement` int(11) NOT NULL,
`DateEmplacement` date NOT NULL,
`IDEmplacement` int(11) NOT NULL,
`NumLocal` int(11) NOT NULL,
`CodeOuvrage` varchar(25) COLLATE latin1_general_ci NOT NULL,
PRIMARY KEY (`IDEquipement`,`DateEmplacement`,`IDEmplacement`,`NumLocal`,`CodeOuvrage`),
KEY `FK_Se_situer_a_DateEmplacement` (`DateEmplacement`),
KEY `FK_Se_situer_a_IDEquipement` (`IDEquipement`),
KEY `FK_Se_situer_a_CodeOuvrage` (`CodeOuvrage`),
CONSTRAINT `FK_Se_situer_a_CodeOuvrage` FOREIGN KEY (`CodeOuvrage`) REFERENCES `ouvrage` (`CodeOuvrage`),
CONSTRAINT `FK_Se_situer_a_DateEmplacement` FOREIGN KEY (`DateEmplacement`) REFERENCES `dateemplacement` (`DateEmplacement`),
CONSTRAINT `FK_Se_situer_a_IDEmplacement` FOREIGN KEY (`IDEmplacement`) REFERENCES `emplacement` (`IDEmplacement`),
CONSTRAINT `FK_Se_situer_a_IDEquipement` FOREIGN KEY (`IDEquipement`) REFERENCES `equipement` (`IDEquipement`),
CONSTRAINT `FK_Se_situer_a_NumLocal` FOREIGN KEY (`NumLocal`) REFERENCES `local` (`NumLocal`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
/*!40101 SET character_set_client = #saved_cs_client */;
I can't find why it does this every time I reboot my computer so reboot xampp.
In MySQL a foreign key can't reference a non-unique field so I had to delete all the foreign keys that matched with this.

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

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;