Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I get an error when I try to create a table:

ERROR 1005 (HY000): Can't create table 'phact_greenland.cache' (errno: 121)

CREATE TABLE IF NOT EXISTS `cache` 
(   
    `cid` varchar(255) NOT NULL DEFAULT '' 
        COMMENT 'Primary Key: Unique cache ID.'
    , `data` longblob 
        COMMENT 'A collection of data to cache.' 
    , `expire` int(11) NOT NULL DEFAULT '0' 
        COMMENT 'A Unix timestamp indicating when the cache entry 
                should expire, or 0 for never.'  
    , `created` int(11) NOT NULL DEFAULT '0' 
        COMMENT 'A Unix timestamp indicating when the cache entry was created.'  
    , `serialized` smallint(6) NOT NULL DEFAULT '0' 
        COMMENT 'A flag to indicate whether content is serialized (1) or not (0).' 
    , PRIMARY KEY (`cid`) 
    , KEY `expire` (`expire`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 
    COMMENT='Generic cache table for caching things not separated out...';

How do i solve it ?

share|improve this question
    
Try it again, then run SHOW engine innodb STATUS; and edit your question with the end of the output. –  FreshPhilOfSO Sep 12 '12 at 12:20
add comment

1 Answer

up vote 2 down vote accepted

You get Error 121 when you try to create a table that contains a constraint with the same name as a constraint defined elsewhere in your database. You can avoid this issue by naming the constraints yourself in the creation script. More information can be found below:

InnoDb Error Codes

http://dev.mysql.com/doc/refman/5.5/en/innodb-error-codes.html

Create Table Statement

http://dev.mysql.com/doc/refman/5.5/en/create-table.html

I hope this helps you.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.