Tried to relate one table to another with the constraint
ALTER TABLE `ventas` ADD CONSTRAINT `ventas_ibfk_1` FOREIGN KEY (`id-personas`) REFERENCES `personas` (`id-personas`);
and I get the following error:
I can't create table
registro
.ventas
(Error: 150 "Foreign key constraint is incorrectly formed")
(it is an experiment of the university not to do it in the other classic way)
What is happening and how can I solve the error or is it not possible to make a relationship with the constraint?
The error stems from the syntax you are using to declare your primary and foreign keys; that is to say, you are writing them with
-
a medium script . In fact, it surprises me that it has allowed you to create the tables with this detail , perhaps you did it from a visual assistant such as the phpMyAdmin interface .The manager, when using a middle script, would return an error like the following:
So the correction is to modify their syntax in this way:
Take this example for reference:
People
Sales
sentence
ALTER TABLE
toventas
Describe
to sales: