Problem with importing mysql workbench data - mysql
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`
--
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.
MySQL Procedure with parameter syntax
I have a schema with lists of characters from star wars, the movies they appear in, the planets they visit, etc. Here is the schema: CREATE DATABASE IF NOT EXISTS `starwarsFINAL` /*!40100 DEFAULT CHARACTER SET utf8 */; USE `starwarsFINAL`; DROP TABLE IF EXISTS `characters`; /*!40101 SET #saved_cs_client = ##character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `characters` ( `character_name` varchar(45) NOT NULL, `race` varchar(45) DEFAULT NULL, `homeworld` varchar(45) DEFAULT 'Unknown', `affiliation` varchar(45) DEFAULT NULL, PRIMARY KEY (`character_name`), KEY `planet_fk` (`homeworld`), CONSTRAINT `planet_fk` FOREIGN KEY (`homeworld`) REFERENCES `planets` (`planet_name`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = #saved_cs_client */; DROP TABLE IF EXISTS `movies`; /*!40101 SET #saved_cs_client = ##character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `movies` ( `movie_id` int(11) NOT NULL, `title` varchar(128) DEFAULT NULL, `scenes_in_db` int(11) DEFAULT NULL, `scenes_in_movies` int(11) DEFAULT NULL, PRIMARY KEY (`movie_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = #saved_cs_client */; DROP TABLE IF EXISTS `planets`; /*!40101 SET #saved_cs_client = ##character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `planets` ( `planet_name` varchar(45) NOT NULL, `planet_type` varchar(30) DEFAULT NULL, `affiliation` varchar(30) DEFAULT NULL, PRIMARY KEY (`planet_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = #saved_cs_client */; DROP TABLE IF EXISTS `timetable`; /*!40101 SET #saved_cs_client = ##character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `timetable` ( `character_name` varchar(45) DEFAULT NULL, `planet_name` varchar(45) DEFAULT 'Unknown', `movie_id` int(11) DEFAULT NULL, `arrival` int(11) DEFAULT NULL, `departure` int(11) DEFAULT NULL, `time_id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`time_id`), UNIQUE KEY `timetable_un` (`character_name`,`planet_name`,`movie_id`,`arrival`), KEY `timetable_fkplanet` (`planet_name`), KEY `timetable_fkmovie` (`movie_id`), CONSTRAINT `timetable_fkcharacter` FOREIGN KEY (`character_name`) REFERENCES `characters` (`character_name`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `timetable_fkmovie` FOREIGN KEY (`movie_id`) REFERENCES `movies` (`movie_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `timetable_fkplanet` FOREIGN KEY (`planet_name`) REFERENCES `planets` (`planet_name`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=57 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = #saved_cs_client */; Here's my problem: Write a procedure track_planet(planet) that accepts a planet name and returns a result set that contain the planet name, the movie name, and the number of characters that appear on that planet during that movie. Here's what I have so far, but I'm lost/stuck on how to make it work. (I'm new to MySQL) DROP PROCEDURE IF EXISTS track_planet; DELIMITER $$ CREATE PROCEDURE track_planet(IN planet VARCHAR(45)) BEGIN SELECT planet_name FROM planets, title FROM movies, COUNT(DISTINCT character_name) FROM characters WHERE planet_name = planet; END DELIMITER;
Hello_ friend. First thanks for posting the schema of your database it really helps. From it I was able to made this picture: And I've changed your code to this: DELIMITER $$ DROP PROCEDURE IF EXISTS track_planet $$ CREATE PROCEDURE track_planet(IN planet VARCHAR(45)) BEGIN SELECT tt.planet_name as planetName, m.title as movieName, COUNT(tt.character_name) as characters FROM timetable tt LEFT JOIN movies m ON tt.movie_id = m.movie_id WHERE tt.planet_name = planet GROUP BY planetName, movieName; END $$ DELIMITER ; The code for the function declaration is pretty much the same except few modifications. The major change is the SELECT statement: selecting the necessary columns; seems that you have most of the information inside timetable so only join movies to get movie name; use GROUP BY first on planet name and then on movie name so it will count characters on a specific planet by specific movie and that's it ... Hope this was helpful. Let me know if it works for you. Cheers!
MySQL Cannot add foreign key constraint Error Code: 1215
I am making a simple MySQL database but i keep getting an error:Cannot add foreign key constraint any help appreciated! Also a Side question is there any difference between using symbol ` and ' while creating your database? /*!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_MiniPost` /*!40100 DEFAULT CHARACTER SET latin1 */; USE `a3823833_MiniPost`; /*Table structure for table `user` */ DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `userid` bigint(10) NOT NULL, `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(11), `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;
the bigint(10) and int(11) are not the same. make em same, and pk on parent table (as u are)
Cannot create a table in mysql error(150)
I want to create 3 tables called curenttasks, originaltasks and previoustasks. I make one table and copied to other two. But one table cannot create while other 2 are created successfully. The three table are: DROP TABLE IF EXISTS `CurrentTasks`; /*!40101 SET #saved_cs_client = ##character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `CurrentTasks` ( `taskID` mediumint(9) NOT NULL AUTO_INCREMENT, `taskName` varchar(255) NOT NULL, `isActive` boolean DEFAULT TRUE, `startDate` datetime NOT NULL, `endDate` datetime NOT NULL, `completeDate` datetime DEFAULT NULL, `complexityID` smallint(6) NOT NULL, `managerID` mediumint(9) NOT NULL, `projectID` mediumint(9) NOT NULL, `requirementName` varchar(255) NOT NULL, `xPos` smallint(6) DEFAULT NULL, `yPos` smallint(6) DEFAULT NULL, `description` text NOT NULL, `stageName` enum('Definition','Design','Development','Testing','Evaluation') NOT NULL DEFAULT 'Definition', PRIMARY KEY (`taskID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = #saved_cs_client */; -- -- Dumping data for table `CurrentTasks` -- LOCK TABLES `PreviousTasks` WRITE; /*!40000 ALTER TABLE `PreviousTasks` DISABLE KEYS */; /*!40000 ALTER TABLE `PreviousTasks` ENABLE KEYS */; UNLOCK TABLES; -- -- Table structure for table `PreviousTasks` -- DROP TABLE IF EXISTS `PreviousTasks`; /*!40101 SET #saved_cs_client = ##character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `PreviousTasks` ( `taskID` mediumint(9) NOT NULL AUTO_INCREMENT, `taskName` varchar(255) NOT NULL, `isActive` boolean DEFAULT TRUE, `startDate` datetime NOT NULL, `endDate` datetime NOT NULL, `completeDate` datetime DEFAULT NULL, `complexityID` smallint(6) NOT NULL, `managerID` mediumint(9) NOT NULL, `projectID` mediumint(9) NOT NULL, `requirementName` varchar(255) NOT NULL, `xPos` smallint(6) DEFAULT NULL, `yPos` smallint(6) DEFAULT NULL, `description` text NOT NULL, `stageName` enum('Definition','Design','Development','Testing','Evaluation') NOT NULL DEFAULT 'Definition', PRIMARY KEY (`taskID`), UNIQUE KEY `uniquePreviousTasks` (`requirementName`,`projectID`,`taskName`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = #saved_cs_client */; -- -- Dumping data for table `PreviousTasks` -- LOCK TABLES `PreviousTasks` WRITE; /*!40000 ALTER TABLE `PreviousTasks` DISABLE KEYS */; /*!40000 ALTER TABLE `PreviousTasks` ENABLE KEYS */; UNLOCK TABLES; -- -- Table structure for table `OriginalTasks` -- DROP TABLE IF EXISTS `OriginalTasks`; /*!40101 SET #saved_cs_client = ##character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `OriginalTasks` ( `taskID` mediumint(9) NOT NULL AUTO_INCREMENT, `taskName` varchar(255) NOT NULL, `isActive` boolean DEFAULT TRUE, `startDate` datetime NOT NULL, `endDate` datetime NOT NULL, `completeDate` datetime DEFAULT NULL, `complexityID` smallint(6) NOT NULL, `managerID` mediumint(9) NOT NULL, `projectID` mediumint(9) NOT NULL, `requirementName` varchar(255) NOT NULL, `xPos` smallint(6) DEFAULT NULL, `yPos` smallint(6) DEFAULT NULL, `description` text NOT NULL, `stageName` enum('Definition','Design','Development','Testing','Evaluation') NOT NULL DEFAULT 'Definition', PRIMARY KEY (`taskID`), UNIQUE KEY `uniqueOriginalTasks` (`requirementName`,`projectID`,`taskName`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = #saved_cs_client */; -- -- Dumping data for table `OriginalTasks` -- LOCK TABLES `OriginalTasks` WRITE; /*!40000 ALTER TABLE `OriginalTasks` DISABLE KEYS */; /*!40000 ALTER TABLE `OriginalTasks` ENABLE KEYS */; UNLOCK TABLES; The currenttasks cannot cteate, the error is: ERROR 1005 (HY000): Can't create table 'rem.currenttasks' (errno: 150) I just very confused because I delete currenttasks and copied previoustasks to it, replace every previous with current, but it still cannot work.
You forgot to delete lines between 28-31. PreviousTasks table is not created yet, but those lines tries to alter table. Also same thing exist at lines 64-67.
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`) ...