1

I have two tables. notas_cabecera and vehiculos.

These are my tables structures:

notas_cabecera table: notas_cabecera table

vehiculos table:

vehiculos table

but when I add a foreign key:

ALTER TABLE notas_cabecera 
ADD CONSTRAINT chapa_vehiculo_fk 
FOREIGN KEY (chapa_vehiculo)
REFERENCES vehiculos(chapa_vehiculo);

I'm getting this error:

Error Code: 1215. Cannot add foreign key constraint

What does this mean?

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
juanpscotto
  • 990
  • 1
  • 13
  • 32
  • It's not the same case. Because the data types are the same varchar(8) for both notas_cabecera.chapa_vehiculo and vehiculo.chapa_vehiculo – juanpscotto Feb 16 '15 at 23:22
  • Maybe check the **Related** list on the right side of the page for other similar problems and you may find your answer that way. – Kevin Panko Feb 16 '15 at 23:34
  • 1
    You are Right. The answer is here http://stackoverflow.com/questions/18081252/error-1215-cannot-add-foreign-key-constraint?rq=1 The vehiculos table didn't have an index on chapa_vehiculo. Thanks – juanpscotto Feb 17 '15 at 00:03

0 Answers0