MYSql 1050 “table already exists” for Drupal 7 .`cache_*`

…but table does not exist!!!

Well, I got working with the Drupal 7 framework after a long time away from it – I just never had any project that required Drupal.

I had only been 2 days in when I cleared my cache using the configuration page and then I started getting these errors everywhere. I initially though nothing of it and felt another cache clear would fix it, but rather it persisted.

As I was not ready to start dealing with un-ecountered issues on this project, due to a short schedule, I opted to reinstall my entire Drupal application, but this time incrementally do backups of my database – especially before installing any modules, since I though it was due to a bad module.

Day 3 without any further incident, I had installed drush and my application was coming together real good.

Suddenly, I ran

[code] drush cc all [/code]

and then there were these errors in the CLI – the same beast was back.

Since I knew I would not be able to just re-install the application – it was now one beautiful piece, I had to find a solution to the problem.

I logged into my DB with HeidiSQL and discovered that cache_views was completely gone…till now, I don’t have an idea how it got DROPped.

I tried to recreate the cache_views table, but then i got the ominous error message from MYSql “table already exists”.

I found that by running the following commands, I was able to get everything working again.

 

[code]

DROP TABLE IF EXISTS `cache_views`;

REPAIR TABLE `cache_views`;

[/code]

Then I recreated the table:

[code]
CREATE TABLE IF NOT EXISTS `cache_views` (
`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…’;
[/code]

 

If these instructions still don’t solve your issue, you can visit this entry on stackoverflow

Leave a Reply