无法将转储导入MySQL 5.7

时间:2016-02-21 17:55:48

标签: mysql

我在MySQL 5.6上创建了一个MySQL转储文件。尝试将其导入MySQL 5.7数据库时,收到以下错误:

[ERROR in query 9] Cannot add foreign key constraint

我已使用SHOW ENGINE INNODB STATUS查看详细信息,并说:

------------------------
LATEST FOREIGN KEY ERROR
------------------------
2016-02-21 18:47:32 0x700000d51000 Error in foreign key constraint of table mydatabase/articles:
 FOREIGN KEY (`company_id`) REFERENCES `e_companies` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci:
Cannot resolve table name close to:
 (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

换句话说,它表示它将SQL语句的整个部分解释为表名。

这就是SQL转储的样子:

DROP TABLE IF EXISTS `articles`;

CREATE TABLE `articles` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `slug` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `perex` text COLLATE utf8_unicode_ci,
  `text` text COLLATE utf8_unicode_ci,
  `status` enum('draft','published') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'draft',
  `author_id` int(10) unsigned NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `image` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `pin` tinyint(1) DEFAULT NULL,
  `order` int(11) DEFAULT NULL,
  `company_id` int(10) unsigned DEFAULT NULL,
  `price` decimal(8,2) DEFAULT NULL,
  `type` enum('article','case-study','interview','recording','infographic') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'article',
  PRIMARY KEY (`id`),
  UNIQUE KEY `articles_slug_unique` (`slug`),
  KEY `articles_company_id_foreign` (`company_id`),
  FULLTEXT KEY `full` (`title`,`perex`),
  CONSTRAINT `articles_company_id_foreign` FOREIGN KEY (`company_id`) REFERENCES `e_companies` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

LOCK TABLES `articles` WRITE;
....

这是MySQL 5.6生成的转储,除了我的MySQL 5.7之外,它运行得很好。有没有人有任何想法可能是这个奇怪的错误的原因?

1 个答案:

答案 0 :(得分:-1)

我的猜测是FULLTEXT KEY导致问题(由于FULLTEXT键,我从5.x升级到5.7时遇到了很多问题......)

我建议删除你创建表的这一部分,然后通过经典的ALTER应用它。

如果这样做,将初始转储(5.6一)与5.7服务器上执行的新转储进行比较会很有意思。

希望这有帮助!

相关问题