I have two servers, a dev and a prod kind of, with the same softwares installed on them. I want to export the db from prod to dev, so i used phpMyadmin, but when reimporting the sql on the dev server, an error occurs:
#1005 - Can't create table `omekas`.`asset` (errno: 150 "Foreign key constraint is incorrectly formed") (Details…)
This really surprises me, as i expected this process to be sort of automatic. What did i do wrong ?
Here is the Create table throwing the error:
--
-- 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;
Thanks
Edit:
Here is the "user" table structure:
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;
edit 2:
I tried to create the table without the foreign key constraint at all, removing the alter table... Which still gave me the same error ?
Running
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;
Returns
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…)