I searched for a solution to this problem on the Internet and checked the Stack Overflow questions, but none of the solutions worked for my case.
I want to create a foreign key from table sira_no to metal_kod.
ALTER TABLE sira_no
ADD CONSTRAINT METAL_KODU FOREIGN KEY(METAL_KODU)
REFERENCES metal_kod(METAL_KODU)
ON DELETE SET NULL
ON UPDATE SET NULL ;
This script returns:
Error Code: 1005. Can't create table 'ebs.#sql-f48_1a3' (errno: 150)
I tried adding an index to the referenced table:
CREATE INDEX METAL_KODU_INDEX ON metal_kod (METAL_KODU);
I checked METAL_KODU on both tables (charset and collation), but I couldn't find a solution to this problem. How can I fix this problem?
Here is the metal_kod table:
METAL_KODU varchar(4) NO PRI
DURUM bit(1) NO
METAL_ISMI varchar(30) NO
AYAR_YOGUNLUK smallint(6) YES 100
metal_kod
table ... which field in that table should the Foreign Key reference ? – Raggletaggle