0

I wanted to add a foreign key to the item_type_name, but it keeps saying its not correctly formed. here is the code that i was using to add the foreign key.

 alter table item_type add constraint
    FOREIGN KEY (item_type_name) 
    REFERENCES item_type (item_type_name)
    ON DELETE CASCADE ON UPDATE CASCADE; 

This is the table that I was trying to add the foreign key to here (1)

This is the table that the key would connect to here (2)

In other words the item_type_name from (1) would connect to item_type_name from (2). I am using mariadb.

nbk
  • 45,398
  • 8
  • 30
  • 47
NotGood_
  • 11
  • 1
  • 4
  • 2
    The columns involved are both `varchar(20)` but do they have the same collation? Please [don't post images of code](https://stackoverflow.com/help/how-to-ask). Just run `SHOW CREATE TABLE ` and get the text that shows the full table definition. – Bill Karwin Jul 06 '20 at 18:10
  • 2
    The target field does not seem to be indexed. Also curious why you try to reference the name field, as opposed to the id field. An int to int comparison will be faster. – Shadow Jul 06 '20 at 18:20

0 Answers0