0

I need help with this problem in MySQL. I have this table:

CREATE TABLE syncproductscard(
  `idsyncproductscard` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `idsyncproducts` int(10) NOT NULL,
  `carsa` varchar(20) DEFAULT NULL,
  `emsa` varchar(20) DEFAULT NULL,
  `column` varchar(250) DEFAULT NULL,
  `val` varchar(2000) DEFAULT NULL,
  `filter` varchar(500) DEFAULT NULL,
  `video` varchar(256) DEFAULT NULL,  
  PRIMARY KEY (`idsyncproductscard`)  
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

but alter table for add foreign key, does not work

ALTER TABLE syncproductscard 
ADD CONSTRAINT `fk_idsyncproducts` 
FOREIGN KEY (`idsyncproducts`)
REFERENCES syncproducts(`idsyncproducts`)
ON DELETE CASCADE;

MySQL says:

Error Code: 1005. Can't create table AAA.#sql-41d0_60 (errno: 150 "Foreign key constraint is incorrectly formed") 0.016 sec

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • You should read this checklist for foreign keys: https://stackoverflow.com/a/4673775/20860 – Bill Karwin Aug 03 '19 at 04:07
  • Please read the section Foreign keys definitions are subject to the following conditions: of https://dev.mysql.com/doc/refman/8.0/en/create-table-foreign-keys.html and if you think you have complied with these add the table definition for `idsyncproducts` – P.Salmon Aug 03 '19 at 05:21

1 Answers1

1

Inspect the two tables and ensure they have the same properties. ENGINE = InnoDB CHARSET = utf8

You should be good to go.