Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql 1050 Error "Table already exists" when in fact, it does not

I'm adding this table:

CREATE TABLE contenttype (         contenttypeid INT UNSIGNED NOT NULL AUTO_INCREMENT,         class VARBINARY(50) NOT NULL,         packageid INT UNSIGNED NOT NULL,         canplace ENUM('0','1') NOT NULL DEFAULT '0',         cansearch ENUM('0','1') NOT NULL DEFAULT '0',         cantag ENUM('0','1') DEFAULT '0',         canattach ENUM('0','1') DEFAULT '0',         isaggregator ENUM('0', '1') NOT NULL DEFAULT '0',         PRIMARY KEY (contenttypeid),         UNIQUE KEY packageclass (packageid, class) ); 

And I get a 1050 "table already exists"

But the table does NOT exist. Any ideas?

EDIT: more details because everyone seems to not believe me :)

DESCRIBE contenttype 

yields:

1146 - Table 'gunzfact_vbforumdb.contenttype' doesn't exist

and

CREATE TABLE gunzfact_vbforumdb.contenttype( contenttypeid INT UNSIGNED NOT NULL AUTO_INCREMENT , class VARBINARY( 50 ) NOT NULL , packageid INT UNSIGNED NOT NULL , canplace ENUM( '0', '1' ) NOT NULL DEFAULT '0', cansearch ENUM( '0', '1' ) NOT NULL DEFAULT '0', cantag ENUM( '0', '1' ) DEFAULT '0', canattach ENUM( '0', '1' ) DEFAULT '0', isaggregator ENUM( '0', '1' ) NOT NULL DEFAULT '0', PRIMARY KEY ( contenttypeid ) , 

Yields:

1050 - Table 'contenttype' already exists

like image 269
Citizen Avatar asked Jul 21 '10 18:07

Citizen


People also ask

How do I drop a table in MySQL?

DROP TABLE MySQL Command Syntax. To remove a table in MySQL, use the DROP TABLE statement. The basic syntax of the command is as follows: DROP [TEMPORARY] TABLE [IF EXISTS] table_name [, table_name] [RESTRICT | CASCADE];


Video Answer


2 Answers

Sounds like you have Schroedinger's table...

Seriously now, you probably have a broken table. Try:

  • DROP TABLE IF EXISTS contenttype
  • REPAIR TABLE contenttype
  • If you have sufficient permissions, delete the data files (in /mysql/data/db_name)
like image 52
NullUserException Avatar answered Sep 25 '22 12:09

NullUserException


from MySQL Log:

InnoDB: You can drop the orphaned table inside InnoDB by InnoDB: creating an InnoDB table with the same name in another InnoDB: database and copying the .frm file to the current database. InnoDB: Then MySQL thinks the table exists, and DROP TABLE will InnoDB: succeed. 
like image 37
wredny Avatar answered Sep 26 '22 12:09

wredny