在DROP SCHEMA之后留下的旧桌子的片段

时间:2011-10-21 10:57:13

标签: mysql

我正在尝试删除并重新创建一个MySQL模式,但是当我这样做时,它似乎会重新出现旧模式的片段。

我有一个脚本来创建新架构...

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

DROP SCHEMA IF EXISTS `scunthorpe` ;

CREATE SCHEMA IF NOT EXISTS `scunthorpe` DEFAULT CHARACTER SET latin1 ;
USE `scunthorpe` ;

DROP TABLE IF EXISTS `location` ;

CREATE  TABLE IF NOT EXISTS `location` (
      `id_location` INT NOT NULL AUTO_INCREMENT ,
      `location` VARCHAR(45) NOT NULL ,
    PRIMARY KEY (`id_location`) )
    ENGINE = InnoDB
    DEFAULT CHARACTER SET = latin1;

DROP TABLE IF EXISTS `strand` ;

CREATE  TABLE IF NOT EXISTS `strand` (
    `id_location` INT NOT NULL ,
    `id_strand` INT NOT NULL ,
    `notes` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`id_location`, `id_strand`) ,
  INDEX `strand_location_fkey` (`id_location` ASC) ,
  CONSTRAINT `strand_location_fkey`
  FOREIGN KEY (`id_location` )
      REFERENCES `location` (`id_location` )
      ON DELETE CASCADE
      ON UPDATE CASCADE)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = latin1;

这会产生错误:

ERROR 1005 (HY000): Can't create table '.\scunthorpe\strand.frm' (errno: 150)

仔细阅读show innodb status会显示以下内容: -

111021 10:46:17 Error in foreign key constraint of table scunthorpe/straightenin
g_temperature:
there is no index in referenced table which would contain
the columns as the first columns, or the data types in the
referenced table do not match to the ones in table. Constraint:
,
  CONSTRAINT straightening_to_strand_fkey FOREIGN KEY (id_location, id_sequence,
 id_strand) REFERENCES strand (id_location, id_sequence, id_strand)

现在,在诺曼征服的时候,架构中有这样一张桌子。但是drop schema应该摆脱它,不是吗?那么有谁知道为什么会再次出现以及我应该怎么做呢?

修改1

正如devart所建议的那样,我尝试了REPAIR TABLE但显然不支持InnoDB。我检查了文件,发现架构目录在DROP SCHEMA语句后被删除,并在CREATE SCHEMA上重新创建,正如人们所期望的那样。代理Ransack透露,在名为straightening_to_strand_fkey的文件中存在违规字符串ibdata1,无论是什么。

1 个答案:

答案 0 :(得分:2)

也许这些建议有助于解决问题: