So, I've created two tables which reference the same one (say, address and a user has an address and company too). This makes me run into this problem:
Constraint created by sequelize: addressId_foreign_idx
Results: Both tables will try to use the same constraint name, which, as you might expect, results in:
code: 'ER_DUP_KEY',
errno: 1022,
sqlState: '23000',
Are you configuring foreignKey or alias? Need to see more code
This is what I'm doing:
return queryInterface.addColumn(
"companies",
"addressId",
{
type: Sequelize.INTEGER,
references: {
model: "addresses",
key: "id"
},
onDelete: "SET NULL"
})
.then(() => {
return queryInterface.addColumn(
"residentialCustomers",
"addressId",
{
type: Sequelize.INTEGER,
references: {
model: "addresses",
key: "id"
},
onDelete: "SET NULL"
})
});
As you can see, both use addressId. but I get that the foreign key created is the same.
same problem
+1
Is there any solution?
I've wasted all the day trying to figure out this same problem
You can now use addConstraint like methods to properly name them http://docs.sequelizejs.com/class/lib/query-interface.js~QueryInterface.html#instance-method-addConstraint
Most helpful comment
same problem