I am making two tables and I want the personOne
column from table b
to reference the person
column on table a
, but for some reason it doesn't work.
I have the below code as an example:
create table a(
person varchar(20),
cost varchar(10) not Null
)character set latin1
collate latin1_general_ci;
create table b(
personOne varchar(20),
personTwo varChar(2) not null,
key person_index (personOne),
CONSTRAINT C FOREIGN KEY (personOne) references a(person)
) engine=InnoDB default charset=latin1;
It is telling me an error:
Error Code: 3780. Referencing column 'personOne' and referenced column 'person' in foreign key constraint 'C' are incompatible.
I tried to to set table a engine to InnoDB, but that didn't work. I researched the problem more but couldn't figure out how to fix it.