ERROR: ERROR 1215 (HY000): Cannot add foreign key constraint

ERROR: ERROR 1215 (HY000): Cannot add foreign key constraint

我正在帮助一位朋友将他的 WordPress 迁移到 AWS。整个WordPress是他用WPClone导出的,我要导入到RDS(Aurora)。我不是专业的数据库专家,我只知道基本的 MySQL 命令。我试图恢复数据库,但在恢复过程中我遇到了 ERROR: ERROR 1215 (HY000): Cannot add foreign key constraint.

我执行了 show engine innodb status 并检查了 LATEST FOREIGN KEY ERROR,这就是我得到的,但我不知道如何解决这个问题。

------------------------
LATEST FOREIGN KEY ERROR
------------------------
2017-03-10 11:22:06 2b87437cb700 Error in foreign key constraint of table clientdb/wp_supsystic_ss_project_networks:
 FOREIGN KEY (`project_id`) REFERENCES `wp_supsystic_ss_projects` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8:
Cannot resolve table name close to:
 (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8

不胜感激!

编辑:这是 wp_supsystic_ss_networkswp_supsystic_ss_project_networkswp_supsystic_ss_projectscreate table

CREATE TABLE `wp_supsystic_ss_networks` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `url` varchar(255) NOT NULL,
  `class` varchar(255) NOT NULL,
  `brand_primary` varchar(7) NOT NULL DEFAULT '#000000',
  `brand_secondary` varchar(7) NOT NULL DEFAULT '#ffffff',
  `total_shares` int(11) unsigned DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8;

CREATE TABLE `wp_supsystic_ss_project_networks` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `project_id` int(11) unsigned DEFAULT NULL,
  `network_id` int(11) unsigned DEFAULT NULL,
  `position` int(11) unsigned DEFAULT '0',
  `title` varchar(255) DEFAULT NULL,
  `text` varchar(255) DEFAULT NULL,
  `tooltip` varchar(255) DEFAULT NULL,
  `text_format` varchar(255) DEFAULT NULL,
  `use_short_url` bit(1) DEFAULT NULL,
  `icon_image` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `FK__wp_supsystic_ss_projects` (`project_id`),
  KEY `FK__wp_supsystic_ss_networks` (`network_id`),
  CONSTRAINT `FK__wp_supsystic_ss_networks` FOREIGN KEY (`network_id`) REFERENCES `wp_supsystic_ss_networks` (`id`),
  CONSTRAINT `FK__wp_supsystic_ss_projects` FOREIGN KEY (`project_id`) REFERENCES `wp_supsystic_ss_projects` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

CREATE TABLE `wp_supsystic_ss_projects` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `settings` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

两个问题:

  1. 按以下顺序创建 tables:child tables, parent table(带外键)。替换 CREATE TABLE 语句:
    • wp_supsystic_ss_projects
    • wp_supsystic_ss_networks
    • wp_supsystic_ss_project_networks.
  2. Child table wp_supsystic_ss_networks 在脚本中不存在。