Reputation: 10926
I want to execute a raw query in my migrations up
and down
functions.
When I try to do: Sequelize.query
, it says ERROR: Sequelize.query is not a function
.
This is my migration skeleton file:
'use strict';
module.exports = {
up: (queryInterface, Sequelize, migration) => {
return Sequelize.query(...); //ERROR: Sequelize.query is not a Function
},
down: (queryInterface, Sequelize) => {
return Sequelize.query(...); //ERROR: Sequelize.query is not a Function
}
};
Upvotes: 16
Views: 15330
Reputation: 1783
The query()
method you are looking for is an instance rather than class method. It exists on Sequelize
instances, not on the class itself.
In migrations, you can access the instance through the provided queryInterface
object as queryInterface.sequelize
.
So your migration should look like:
'use strict';
module.exports = {
up: (queryInterface, Sequelize, migration) => {
return queryInterface.sequelize.query(...);
},
down: (queryInterface, Sequelize) => {
return queryInterface.sequelize.query(...);
}
};
Upvotes: 38