mysql - Can not set FOREIGN KEY with DELETE ON CASCADE -
i delete referencing data foreign key.
here 2 of datatables:
create table `specification_variant_parent` ( `specification_variant_parent_id` int(11) unsigned not null auto_increment, `sort_order` tinyint(3) unsigned not null, primary key (`specification_variant_parent_id`) ) engine=innodb; create table `specification_variant_parent_description` ( `specification_variant_parent_id` smallint(5) unsigned not null, `language_id` tinyint(3) unsigned not null, `name` varchar(64) collate utf8mb4_unicode_ci not null, primary key (`specification_variant_parent_id`,`language_id`), key (`specification_variant_parent_id`) references specification_variant_parent (specification_variant_parent_id) on delete cascade ) engine=innodb;
when fire in phpmyadmin says:
error in foreign key constraint of table database/specification_variant_parent_description: foreign key (
specification_variant_parent_id
) references specification_variant_parent (specification_variant_parent_id) on delete cascade ) engine=innodb: cannot find index in referenced table referenced columns appear first columns, or column types in table , referenced table not match constraint.
what wrong database scheme?
your datatypes not match.
in first table have
`specification_variant_parent_id` int(11) unsigned not null auto_incremen
the datatype declare unsigned int
in second table foreign key is
`specification_variant_parent_id` smallint(5) unsigned not null
and datatype unsigned smallint
make both of them same datatype.
Comments
Post a Comment