Difficulty in doing Foreign key with two char fields in Mysql

0

I am not able to create a foreign key between two tables, whose type is CHAR :

ALTER TABLE hardware ADD CONSTRAINT fk_INC_LOCALIDADE FOREIGN KEY ( INC_LOCALIDADE ) REFERENCES localidade (INC);

The error is:

  

ALTER TABLE hardware ADD CONSTRAINT fk_INC_LOCALITY FOREIGN KEY (INC_LOCALITY) REFERENCES locality (INC); failed: Can not add or update child row: a foreign key constraint fails

I gave show full columns and the result is this:

Location TABLE:

Field    Type       Collation          Null     Key     Default     Privileges  
INC      char(11)   utf8_general_ci    NO       PRI     A           select,insert,update,references

Hardware TABLE:

Field            Type       Collation          Null     Key     Default     Privileges 
INC_LOCALIDADE   char(11)   utf8_general_ci     NO               A          select,insert,update,references

The fields must be CHAR , when I change to INT it works, but the data will come in CHAR .

    
asked by anonymous 11.12.2018 / 12:05

0 answers