0

我有以下问题。

我有由转储创建的包含代码的 sql 文件:

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

/*SOME MORE SCRIPTS*/

DROP TABLE IF EXISTS `avalues`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;

CREATE TABLE `avalues` (
  `AVALUES_ID` INT(11) NOT NULL AUTO_INCREMENT,
  `AVALUES_MVALUES_ID` INT(11) NOT NULL DEFAULT '0',
  `AVALUES_OBJECT_ID` INT(11) NOT NULL DEFAULT '0',
  `AVALUES_VALUE` LONGTEXT,
  `AVALUES_RANG` INT(11) NOT NULL DEFAULT '0',
  `AVALUES_VALUE_NUM` DOUBLE DEFAULT NULL,
  `AVALUES_VALUE_DATE` DATETIME DEFAULT NULL,
  `AVALUES_VALUE_TIME` TIME DEFAULT NULL,
  `AVALUES_TOBJECT_ID` INT(11) DEFAULT NULL,
  PRIMARY KEY (`AVALUES_ID`),
  UNIQUE KEY `UK_AVALUES_MVALUES_OBJECT_RANG` (`AVALUES_MVALUES_ID`,`AVALUES_OBJECT_ID`,`AVALUES_RANG`),
  KEY `I_AVALUES_MVALUES` (`AVALUES_MVALUES_ID`),
  KEY `I_AVALUES_OBJECT` (`AVALUES_OBJECT_ID`),
  KEY `I_AVALUES_MVALUES_NUM` (`AVALUES_MVALUES_ID`,`AVALUES_VALUE_NUM`),
  KEY `I_AVALUES_MVALUES_DATE` (`AVALUES_MVALUES_ID`,`AVALUES_VALUE_DATE`),
  KEY `i_avalues_object_mvalues` (`AVALUES_OBJECT_ID`,`AVALUES_MVALUES_ID`),
  KEY `I_AVALUES_VALUE` (`AVALUES_VALUE`(255)),
  KEY `I_AVALUES_MVALUES_VALUE` (`AVALUES_MVALUES_ID`,`AVALUES_VALUE`(255)),
  KEY `i_avalues_tobject_value` (`AVALUES_TOBJECT_ID`,`AVALUES_VALUE`(255))
  , KEY `i_avalues_object_mvalues_value` (`AVALUES_OBJECT_ID`,`AVALUES_MVALUES_ID`,`AVALUES_VALUE`(255))
   , CONSTRAINT `FK_AVALUES_MVALUES_ID` FOREIGN KEY (`AVALUES_MVALUES_ID`) REFERENCES `mask_values` (`MVALUES_ID`) ON DELETE CASCADE
   , CONSTRAINT `FK_AVALUES_OBJECT_ID` FOREIGN KEY (`AVALUES_OBJECT_ID`) REFERENCES `object` (`OBJECT_ID`) ON DELETE CASCADE
   , FULLTEXT KEY `I_AVALUES_VALUE_FULLTEXT` (`AVALUES_VALUE`)
) ENGINE=INNODB AUTO_INCREMENT=3463676 DEFAULT CHARSET=utf8;

/*SOME MORE SCRIPTS*/

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

我正在使用InnoDB引擎。

在我拥有 mysql 版本5.6.5-m8-log之前,一切正常,并且所有脚本都已使用 mysql 正确处理。

今天我将 mysql 更新到5.7.9-log版本,当我想运行这些脚本时,不会创建表 avalues。

我收到以下错误: 错误代码:1215 无法添加外键约束

当我从脚本行中取出

FULLTEXT KEY `I_AVALUES_VALUE_FULLTEXT` (`AVALUES_VALUE`)

两条线

, CONSTRAINT `FK_AVALUES_MVALUES_ID` FOREIGN KEY (`AVALUES_MVALUES_ID`) REFERENCES `mask_values` (`MVALUES_ID`) ON DELETE CASCADE
, CONSTRAINT `FK_AVALUES_OBJECT_ID` FOREIGN KEY (`AVALUES_OBJECT_ID`) REFERENCES `object` (`OBJECT_ID`) ON DELETE CASCADE

表已正确创建。但似乎如果所有三行都在一起,则会导致提到的错误。

我已经读过,在 mysql 5.6 版之前,这两个键(外文和全文)不能放在一个表中。但我使用的是 mysql 版本 5.7.9。我试图用谷歌搜索问题,但我找不到适合我的解决方案。

感谢你的回答

4

1 回答 1

1

这是一个错误:错误 #78955:使用 InnoDB 全文索引和约束导入转储失败

尝试以下更改,首先创建引用的表:

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

DROP TABLE IF EXISTS `avalues`;
DROP TABLE IF EXISTS `mask_values`;
DROP TABLE IF EXISTS `object`;

CREATE TABLE `mask_values` (
  `MVALUES_ID` INT(11) AUTO_INCREMENT PRIMARY KEY
) ENGINE=INNODB DEFAULT CHARSET=utf8;

CREATE TABLE `object` (
  `OBJECT_ID` INT(11) AUTO_INCREMENT PRIMARY KEY
) ENGINE=INNODB DEFAULT CHARSET=utf8;

CREATE TABLE `avalues` (
  `AVALUES_ID` INT(11) NOT NULL AUTO_INCREMENT,
  `AVALUES_MVALUES_ID` INT(11) NOT NULL DEFAULT '0',
  `AVALUES_OBJECT_ID` INT(11) NOT NULL DEFAULT '0',
  `AVALUES_VALUE` LONGTEXT,
  `AVALUES_RANG` INT(11) NOT NULL DEFAULT '0',
  `AVALUES_VALUE_NUM` DOUBLE DEFAULT NULL,
  `AVALUES_VALUE_DATE` DATETIME DEFAULT NULL,
  `AVALUES_VALUE_TIME` TIME DEFAULT NULL,
  `AVALUES_TOBJECT_ID` INT(11) DEFAULT NULL,
  PRIMARY KEY (`AVALUES_ID`),
  UNIQUE KEY `UK_AVALUES_MVALUES_OBJECT_RANG` (`AVALUES_MVALUES_ID`,`AVALUES_OBJECT_ID`,`AVALUES_RANG`),
  KEY `I_AVALUES_MVALUES` (`AVALUES_MVALUES_ID`),
  KEY `I_AVALUES_OBJECT` (`AVALUES_OBJECT_ID`),
  KEY `I_AVALUES_MVALUES_NUM` (`AVALUES_MVALUES_ID`,`AVALUES_VALUE_NUM`),
  KEY `I_AVALUES_MVALUES_DATE` (`AVALUES_MVALUES_ID`,`AVALUES_VALUE_DATE`),
  KEY `i_avalues_object_mvalues` (`AVALUES_OBJECT_ID`,`AVALUES_MVALUES_ID`),
  KEY `I_AVALUES_VALUE` (`AVALUES_VALUE`(255)),
  KEY `I_AVALUES_MVALUES_VALUE` (`AVALUES_MVALUES_ID`,`AVALUES_VALUE`(255)),
  KEY `i_avalues_tobject_value` (`AVALUES_TOBJECT_ID`,`AVALUES_VALUE`(255)),
  KEY `i_avalues_object_mvalues_value` (`AVALUES_OBJECT_ID`,`AVALUES_MVALUES_ID`,`AVALUES_VALUE`(255)),
  CONSTRAINT `FK_AVALUES_MVALUES_ID` FOREIGN KEY (`AVALUES_MVALUES_ID`) REFERENCES `mask_values` (`MVALUES_ID`) ON DELETE CASCADE,
  CONSTRAINT `FK_AVALUES_OBJECT_ID` FOREIGN KEY (`AVALUES_OBJECT_ID`) REFERENCES `object` (`OBJECT_ID`) ON DELETE CASCADE,
  FULLTEXT KEY `I_AVALUES_VALUE_FULLTEXT` (`AVALUES_VALUE`)
) ENGINE=INNODB DEFAULT CHARSET=utf8;

/*
CREATE TABLE `mask_values` (
  `MVALUES_ID` INT(11) AUTO_INCREMENT PRIMARY KEY
) ENGINE=INNODB DEFAULT CHARSET=utf8;

CREATE TABLE `object` (
  `OBJECT_ID` INT(11) AUTO_INCREMENT PRIMARY KEY
) ENGINE=INNODB DEFAULT CHARSET=utf8;
*/

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

mysql> /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
Query OK, 0 rows affected (0.00 sec)

mysql> /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
Query OK, 0 rows affected (0.00 sec)

mysql> /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
Query OK, 0 rows affected (0.00 sec)

mysql> /*!40101 SET NAMES utf8 */;
Query OK, 0 rows affected (0.00 sec)

mysql> /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
Query OK, 0 rows affected (0.00 sec)

mysql> /*!40103 SET TIME_ZONE='+00:00' */;
Query OK, 0 rows affected (0.00 sec)

mysql> /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
Query OK, 0 rows affected (0.00 sec)

mysql> /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
Query OK, 0 rows affected (0.00 sec)

mysql> /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
Query OK, 0 rows affected (0.00 sec)

mysql> DROP TABLE IF EXISTS `avalues`;
Query OK, 0 rows affected (0.01 sec)

mysql> DROP TABLE IF EXISTS `mask_values`;
Query OK, 0 rows affected (0.01 sec)

mysql> DROP TABLE IF EXISTS `object`;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE `mask_values` (
    ->   `MVALUES_ID` INT(11) AUTO_INCREMENT PRIMARY KEY
    -> ) ENGINE=INNODB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE `object` (
    ->   `OBJECT_ID` INT(11) AUTO_INCREMENT PRIMARY KEY
    -> ) ENGINE=INNODB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE `avalues` (
    ->   `AVALUES_ID` INT(11) NOT NULL AUTO_INCREMENT,
    ->   `AVALUES_MVALUES_ID` INT(11) NOT NULL DEFAULT '0',
    ->   `AVALUES_OBJECT_ID` INT(11) NOT NULL DEFAULT '0',
    ->   `AVALUES_VALUE` LONGTEXT,
    ->   `AVALUES_RANG` INT(11) NOT NULL DEFAULT '0',
    ->   `AVALUES_VALUE_NUM` DOUBLE DEFAULT NULL,
    ->   `AVALUES_VALUE_DATE` DATETIME DEFAULT NULL,
    ->   `AVALUES_VALUE_TIME` TIME DEFAULT NULL,
    ->   `AVALUES_TOBJECT_ID` INT(11) DEFAULT NULL,
    ->   PRIMARY KEY (`AVALUES_ID`),
    ->   UNIQUE KEY `UK_AVALUES_MVALUES_OBJECT_RANG` (`AVALUES_MVALUES_ID`,`AVALUES_OBJECT_ID`,`AVALUES_RANG`),
    ->   KEY `I_AVALUES_MVALUES` (`AVALUES_MVALUES_ID`),
    ->   KEY `I_AVALUES_OBJECT` (`AVALUES_OBJECT_ID`),
    ->   KEY `I_AVALUES_MVALUES_NUM` (`AVALUES_MVALUES_ID`,`AVALUES_VALUE_NUM`),
    ->   KEY `I_AVALUES_MVALUES_DATE` (`AVALUES_MVALUES_ID`,`AVALUES_VALUE_DATE`),
    ->   KEY `i_avalues_object_mvalues` (`AVALUES_OBJECT_ID`,`AVALUES_MVALUES_ID`),
    ->   KEY `I_AVALUES_VALUE` (`AVALUES_VALUE`(255)),
    ->   KEY `I_AVALUES_MVALUES_VALUE` (`AVALUES_MVALUES_ID`,`AVALUES_VALUE`(255)),
    ->   KEY `i_avalues_tobject_value` (`AVALUES_TOBJECT_ID`,`AVALUES_VALUE`(255)),
    ->   KEY `i_avalues_object_mvalues_value` (`AVALUES_OBJECT_ID`,`AVALUES_MVALUES_ID`,`AVALUES_VALUE`(255)),
    ->   CONSTRAINT `FK_AVALUES_MVALUES_ID` FOREIGN KEY (`AVALUES_MVALUES_ID`) REFERENCES `mask_values` (`MVALUES_ID`) ON DELETE CASCADE,
    ->   CONSTRAINT `FK_AVALUES_OBJECT_ID` FOREIGN KEY (`AVALUES_OBJECT_ID`) REFERENCES `object` (`OBJECT_ID`) ON DELETE CASCADE,
    ->   FULLTEXT KEY `I_AVALUES_VALUE_FULLTEXT` (`AVALUES_VALUE`)
    -> ) ENGINE=INNODB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.02 sec)

mysql> /*
   /*> CREATE TABLE `mask_values` (
   /*>   `MVALUES_ID` INT(11) AUTO_INCREMENT PRIMARY KEY
   /*> ) ENGINE=INNODB DEFAULT CHARSET=utf8;
   /*> 
   /*> CREATE TABLE `object` (
   /*>   `OBJECT_ID` INT(11) AUTO_INCREMENT PRIMARY KEY
   /*> ) ENGINE=INNODB DEFAULT CHARSET=utf8;
   /*> */

mysql> /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
Query OK, 0 rows affected (0.00 sec)

mysql> /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
Query OK, 0 rows affected (0.00 sec)

mysql> /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
Query OK, 0 rows affected (0.00 sec)

mysql> /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
Query OK, 0 rows affected (0.00 sec)

mysql> /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Query OK, 0 rows affected (0.00 sec)

mysql> /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
Query OK, 0 rows affected (0.00 sec)

我正在寻找行为的原因。

更新

当您在创建表后尝试SHOW ENGINE INNODB STATUS(参见13.7.5.15 SHOW ENGINE 语法)时,您可以阅读以下内容:

...
------------------------
LATEST FOREIGN KEY ERROR
------------------------
2000-01-01 00:00:01 0x901ffb40 Error in foreign key constraint of table test/avalues:
 FOREIGN KEY (`AVALUES_MVALUES_ID`) REFERENCES `mask_values` (`MVALUES_ID`) ON DELETE CASCADE,
  CONSTRAINT `FK_AVALUES_OBJECT_ID` FOREIGN KEY (`AVALUES_OBJECT_ID`) REFERENCES `object` (`OBJECT_ID`) ON DELETE CASCADE,
  FULLTEXT KEY `I_AVALUES_VALUE_FULLTEXT` (`AVALUES_VALUE`)
) ENGINE=INNODB DEFAULT CHARSET=utf8:
Cannot resolve table name close to:
 (`MVALUES_ID`) ON DELETE CASCADE,
  CONSTRAINT `FK_AVALUES_OBJECT_ID` FOREIGN KEY (`AVALUES_OBJECT_ID`) REFERENCES `object` (`OBJECT_ID`) ON DELETE CASCADE,
  FULLTEXT KEY `I_AVALUES_VALUE_FULLTEXT` (`AVALUES_VALUE`)
) ENGINE=INNODB DEFAULT CHARSET=utf8
...
于 2015-11-11T14:20:01.410 回答