Hi,
We have following relationships defined:
Address.associate = (models) => {
Address.belongsTo(models.Country, {
foreignKey: "country",
targetKey: "iso",
});
Address.belongsTo(models.Person);
};
Country.hasMany(models.Address, {
foreignKey: "country",
sourceKey: "iso",
});
When we try to update the country of an address or add an address to a country in forest we have following error:
SequelizeForeignKeyConstraintError: Cannot add or update a child row: a foreign key constraint fails (`ElypsPersonsDb`.`Address`, CONSTRAINT `Address_ibfk_1` FOREIGN KEY (`country`) REFERENCES `Country` (`iso`) ON DELETE SET NULL ON UPDATE CASCADE)
Expected behavior
We exepect to be able to add address to country and link addresses with country.
Actual behavior
Error: Cannot add or update a child row: a foreign key constraint fails
Failure Logs
e[31mSequelizeForeignKeyConstraintError: Cannot add or update a child row: a foreign key constraint fails (ElypsPersonsDb
.Address
, CONSTRAINT Address_ibfk_1
FOREIGN KEY (country
) REFERENCES Country
(iso
) ON DELETE SET NULL ON UPDATE CASCADE)e[39m
Context
Please provide any relevant information about your setup.
- Package Version: 6.3.6
- Express Version: 4.16.3
- Sequelize Version: 5.15.1
- Database Dialect: MySql
- Database Version: 5.6
- Project Name: Elyps