Error 121 Mysql Foreign Key
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions mysql foreign key error 1452 you might have Meta Discuss the workings and policies of this
Mysql Foreign Key Error 1215
site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers mysql foreign key example or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community mysql workbench foreign key of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up MySQL errorno 121 up vote 32 down vote favorite 5 I'm getting this error in MySQL create. I'm doing: CREATE TABLE `blogReply` ( `Id` INT(24) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key of This Table',
Mysql Add Foreign Key
`blogId` INT(24) NOT NULL COMMENT 'Blog where this reply was posted', `userId` INT(24) NULL COMMENT 'User the blog was posted by', `name` VARCHAR(100) NULL DEFAULT 'Unknown' COMMENT 'The Name of the user that the reply was posted by', `email` VARCHAR(100) NULL DEFAULT 'Unknown' COMMENT 'The Email of the user that the reply was posted by', `http` VARCHAR(300) NULL DEFAULT 'Unknown' COMMENT 'The Webaddress of the user that the reply was posted by', `message` TEXT NOT NULL COMMENT 'text of the blog', `votes` INT(10) DEFAULT 0 COMMENT 'Rating of the Blog', `ratedBy` TEXT COMMENT 'People who have already Voted on this blog', `dateReg` BIGINT NOT NULL COMMENT 'Date the User was Registered', PRIMARY KEY (`Id`), CONSTRAINT `FK_userId` FOREIGN KEY(`userId`) REFERENCES `user` (`Id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `FK_blogId` FOREIGN KEY(`blogId`) REFERENCES `blog` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE = InnoDB; Any Ideas? The Error States: Can't create table './xxxxxxxx/blogReply.frm' (errno: 121) mysql foreign-keys mysql-er
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about mysql multiple foreign key Stack Overflow the company Business Learn more about hiring developers or posting ads with mysql foreign key syntax us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is
Mysql Insert Foreign Key
a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up error 121 mysql with constraints up vote 2 down vote favorite 2 I am http://stackoverflow.com/questions/1180660/mysql-errorno-121 trying to re define my database design adding some extra tables so There are no repeated names for example in my table Departaments and Jobs... But I am getting the error 121 which has to do with foreign keys, can you explain why is this problem? I am doing this in sqlfiddle I am trying to do something like this but had no luck in sqlfiddle there is what i http://stackoverflow.com/questions/13264085/error-121-mysql-with-constraints have working at the moment CREATE TABLE Employee( EmployeeID INTEGER NOT NULL PRIMARY KEY, Name VARCHAR(30) NOT NULL, Sex CHAR(1) NOT NULL, Address VARCHAR(80) NOT NULL, Security VARCHAR(15) NOT NULL ); CREATE TABLE Departments ( DeptID INTEGER NOT NULL PRIMARY KEY, DeptName VARCHAR(30) NOT NULL ); If I uncomment the code I get Schema Creation Failed: Can't create table 'db_2_2bf4a.project-employee' (errno: 121): CREATE TABLE `Dept-Employee`( EmployeeID INTEGER NOT NULL, DeptID INTEGER NOT NULL, CONSTRAINT fk_DeptID FOREIGN KEY (DeptID) REFERENCES Departments(DeptID), CONSTRAINT fk_EmployeeID FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID) ); CREATE TABLE `Dept-Manager`( EmployeeID INTEGER NOT NULL, DeptID INTEGER NOT NULL, CONSTRAINT fk_DeptID FOREIGN KEY (DeptID) REFERENCES Departments(DeptID), CONSTRAINT fk_EmployeeID FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID) ); CREATE TABLE Jobs ( JobID INTEGER NOT NULL PRIMARY KEY, JobName VARCHAR(30) NOT NULL, JobSalary DOUBLE(15,3) NOT NULL default '0.000', JobSalaryperDay DOUBLE(15,3) NOT NULL default '0.000', DeptID INTEGER NOT NULL ); CREATE TABLE `Jobs-Employee`( EmployeeID INTEGER NOT NULL, JobID INTEGER NOT NULL, CONSTRAINT fk_JobID FOREIGN KEY (JobID) REFERENCES Jobs(JobID), CONSTRAINT fk_EmployeeID FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID) ); CREATE TABLE Project( ProjectID INTEGER NOT NULL PRIMARY KEY, ProjectDesc VARCHAR(200) NOT NULL, StartDate DATE NOT NULL, EndDate DATE NOT NULL, DaysOfWork INTEGER NOT NULL, NoEmployees INTEGER NOT NULL, EstimatedCost DOUBLE(15,3) NOT NULL default '0.000', RealCost DOUBLE(1
SQL Insertion Learn how web applications with access to your database (e.g. MySQL) may be used to poison, dump, or delete information in your database. MySQL Foreign Keys Learn all about MySQL foreign keys in this white paper. MySQL Foreign Key http://www.eliacom.com/mysql-gui-wp-errno-150.php Errors and Errno: 150 Learn how to avoid MySQL foreign key errors, including the notorious http://board.phpbuilder.com/showthread.php?10359413-RESOLVED-mysql-error-1005-errno-121-when-trying-to-set-a-foreign-key Errno:150 in this white paper. MySQL/SQL Data Validation (with PHP) Learn the importance of data validation in web applications when information is accepted from third parties, or even from internal users. MySQL Foreign Key Errors: errno 150, errno 121, and others Diagnosing Errors SHOW ENGINE INNODB STATUS is Your New Best Friend: Click for solutionIf you get one of foreign key the really helpful errors (sarcasm) like the errno 150 or errno 121, then by simply typing in SHOW ENGINE INNODB STATUS, there is a section called "LATEST FOREIGN KEY ERROR". Under that it will give you a very helpful error message, which typically will tell you right away what is the matter. What's the catch?You need SUPER privileges to run it, so if you don't have that, you'll just have to test out the mysql foreign key following scenarios. Use Eliacom's MySQL GUI tool to catch most errors: Click for solutionYou can either download the MySQL GUI to install on your own server, or you can use our free online demo of the MySQL GUI to do it. You can check out our video on how to create foreign keys and indexes using Eliacom's MySQL GUI tool.. MySQL errno 150 ERROR 1005 (HY000): Can't create table 'table' (errno: 150) ERROR 1025 (HY000): Error on rename of 'table' to 'newtable' (errno: 150) Causes and Solutions for errno 150 Data Types Don't Match: Click for solutionThe types of the columns have to be the same (usually). This is one of the most common reasons for errno 150. For instance, if the type of the child column is VARCHAR(50), the type of the parent column should be exactly VARCHAR(50) (since they're supposed to hold the same data). For numeric types, if one is UNSIGNED, then both have to be UNSIGNED. They should match exactly!. I have run into circumstances where it has let me create a foreign key where the child column was a VARCHAR(50) and the parent column was a VARCHAR(200). Interestingly, if I tried to do the opposite for the same tables, reference a child column that was a VARCHAR(200) to a parent column that was a VARCH
set a foreign key If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. Results 1 to 9 of 9 Thread: [RESOLVED] mysql error 1005 errno 121 when trying to set a foreign key Tweet Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Search Thread Advanced Search Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 09-27-2008,01:32 PM #1 s0me0ne View Profile View Forum Posts Senior Member Join Date May 2003 Posts 121 [RESOLVED] mysql error 1005 errno 121 when trying to set a foreign key I'm trying to setup a table that has 2 foreign keys. I was able to set host_id as a Foreign Key, but I cannot get site_id to be a foreign key in the table SITES_HOSTS. I get mysql error 1005 errno 121 I'm using the MySQL Query Browser when I'm doing this, because I'm not good enough to use the command line, but the app shows me its doing this ALTER TABLE `db_special`.`sites_hosts` ADD CONSTRAINT `site_id` FOREIGN KEY `site_id` (`site_id`) REFERENCES `sites` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT; Here are my tables Code: SITES +-------------+---------------------+------+-----+---------------------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | title | varchar(100) | NO | | | | | description | longtext | YES | | NULL | | | url | varchar(150) | YES | | NULL | | | status | tinyint(3) unsigned | NO | | | | | pubdate | timestamp | NO | | CURRENT_TIMESTAMP | | | updated | timestamp | NO | | 0000-00-00 00:00:00 | | | subtitle | varchar(100) | YES | | NULL | | | sitetype_id | int(10) unsigned | NO | MUL | | | +-------------+---------------------+------+-----+---------------------+----------------+ HOSTS +---------+---------------------+------+-----+-------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------+---------------------+------+-----+-------------------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | title | varchar(100) | NO | | | | | status | tinyint(3) unsigned | NO | | | | | pubdate | timestamp | NO | | CURRENT_TIMESTAMP | | +---------+---------------------+------+-----+-------------------+----------------+ SITES_HOSTS +---------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | site_id | int(10)