I can't add a constraint in a migration.
When I run sequelize db:migrate I got this error:
TypeError: queryInterface.addConstraint is not a function
This is my migration file:
'use strict';
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.addConstraint('booking_transfers', ['billing_cycle_id'], {
type: 'FOREIGN KEY',
references: {
name: 'fk_booking_transfers_billing_cycles',
table: 'billing_cycles',
field: 'id'
}
});
},
down: function (queryInterface, Sequelize) {
return queryInterface.removeConstraint('booking_transfers', 'fk_booking_transfers_billing_cycles');
}
};
P.S.: I'm using MySQL
@sdepold
+1
+1
Why don't you give me a solution instead of typing "+1" ?
@eduardrock we're giving "+1" to signify that we(just like you) have also run into this problem and are hoping to bring attention to the repository contributors.
With that said, here's the solution I've deciced to use until it gets fixed.
module.exports = {
up: function(queryInterface, Sequelize) {
return queryInterface.sequelize.query("ALTER TABLE app_users ADD CONSTRAINT unique_user_email UNIQUE (email);")
},
down: function(queryInterface, Sequelize) {
return queryInterface.sequelize.query("ALTER TABLE app_users DROP CONSTRAINT unique_user_email;")
}
};
@dadamssg Oh thanks. It never passed through my mind to do that as a solution.
https://github.com/sequelize/sequelize/issues/7108 addConstraint is not released yet, it will be included in v4 final release (See changelog for more details https://github.com/sequelize/sequelize/blob/master/changelog.md#future)
Ah, i _thought_ i the version I was using had this(4.0.0-2). Looks like it's only in master right now. Thanks @sushantdhiman
Hey @sushantdhiman is there a syntax for addConstraint to have it auto-created via Model.init? Cannot seem to see anything in the docs for this.
Most helpful comment
@eduardrock we're giving "+1" to signify that we(just like you) have also run into this problem and are hoping to bring attention to the repository contributors.
With that said, here's the solution I've deciced to use until it gets fixed.