Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql can't create table errno 121

Tags:

mysql

Why am I getting this error? I don't have any foreign keys

drop table if exists t_issue;
SET foreign_key_checks = 0;SET storage_engine=INNODB;
CREATE TABLE `t_issue` (
`id_issue` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`fk_project` int(11) DEFAULT NULL,
`subject` varchar(255) DEFAULT NULL,
`estimated_due_date` date DEFAULT NULL,
`due_date` date DEFAULT NULL,
`done_ratio` int(11) DEFAULT NULL,
`fk_status` int(11) DEFAULT NULL,
`fk_assigned_to` int(11) DEFAULT NULL,
`fk_owner` int(11) DEFAULT NULL
) ENGINE=innodb DEFAULT CHARSET=latin1
like image 746
luca.p.alexandru Avatar asked Mar 28 '14 12:03

luca.p.alexandru


1 Answers

Mysql can't create table errno 121

You will get this message if you are trying to add a constraint with a name that is already used somewhere else.

To check constraints, use the following SQL query:

SELECT
    constraint_name,
    table_name
FROM
    information_schema.table_constraints
WHERE
    constraint_type = 'FOREIGN KEY'
AND table_schema = DATABASE()
ORDER BY
    constraint_name;

Reference: https://dba.stackexchange.com/questions/425/error-creating-foreign-key-from-mysql-workbench

See also: SQL - error code 1005 with error number 121

like image 101
jmail Avatar answered Oct 11 '22 09:10

jmail