我有两台服务器,一台是开发服务器,一台是生产服务器,上面安装了相同的软件。我想将数据库从prod导出到dev,所以我使用了phpMyadmin,但是在dev服务器上重新导入sql时,出现错误:
#1005 - Can't create table `omekas`.`asset` (errno: 150 "Foreign key constraint is incorrectly formed") (Details…)
这真的让我感到惊讶,因为我希望这个过程是自动的。我做错了什么?
这是抛出错误的创建表:
--
-- Table structure for table `asset`
--
DROP TABLE IF EXISTS `asset`;
CREATE TABLE `asset` (
`id` int(11) NOT NULL,
`owner_id` int(11) DEFAULT NULL,
`name` varchar(255) NOT NULL,
`media_type` varchar(255) NOT NULL,
`storage_id` varchar(190) NOT NULL,
`extension` varchar(255) DEFAULT NULL,
`alt_text` longtext DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Constraints for table `asset`
--
ALTER TABLE `asset`
ADD CONSTRAINT `FK_2AF5A5C7E3C61F9` FOREIGN KEY (`owner_id`) REFERENCES `user` (`id`) ON DELETE SET NULL;
谢谢
编辑:
这里是“用户”表结构:
CREATE TABLE `user` (
`id` int(11) NOT NULL,
`email` varchar(190) NOT NULL,
`name` varchar(190) NOT NULL,
`created` datetime NOT NULL,
`modified` datetime DEFAULT NULL,
`password_hash` varchar(60) DEFAULT NULL,
`role` varchar(190) NOT NULL,
`is_active` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
编辑2:
我尝试创建完全没有外键约束的表,删除了 alter table...这仍然给了我同样的错误?
跑步
CREATE TABLE `asset` (
`id` int(11) NOT NULL,
`owner_id` int(11) DEFAULT NULL,
`name` varchar(255) NOT NULL,
`media_type` varchar(255) NOT NULL,
`storage_id` varchar(190) NOT NULL,
`extension` varchar(255) DEFAULT NULL,
`alt_text` longtext DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
退货
CREATE TABLE `asset` (
`id` int(11) NOT NULL,
`owner_id` int(11) DEFAULT NULL,
`name` varchar(255) NOT NULL,
`media_type` varchar(255) NOT NULL,
`storage_id` varchar(190) NOT NULL,
`extension` varchar(255) DEFAULT NULL,
`alt_text` longtext DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
MySQL said: Documentation
#1005 - Can't create table `omekas`.`asset` (errno: 150 "Foreign key constraint is incorrectly formed") (Details…)