Ad
Adding Associations To Non Default Schema With Sequelize Migrations
I am trying to create a sequelize migration that adds an association to a table that is under a non default schema. Here is the migration code I am trying to use:
module.exports = {
up: (queryInterface, Sequelize) =>
queryInterface
.addColumn(
'Users',
'profileId',
{
type: Sequelize.INTEGER,
references: {
model: {
tableName: 'Profile',
schema: 'annotations',
},
key: 'id',
},
allowNull: false,
onUpdate: 'CASCADE',
onDelete: 'SET NULL',
},
{
schema: 'annotations',
},
),
down: queryInterface =>
queryInterface
.removeColumn('Users', 'profileId', {
schema: 'annotations',
}),
};
Im getting the following error:
ERROR: relation "public.Users" does not exist
How can I get sequelize to go to "annotations.Users" instead of "public.Users"?
Ad
Answer
This is an issue with sequelize which adds "public." to a table creation by default.
One option you have is to use sequelize queryInterface to create the schema and the table and for the associations, use queryInterface.sequelize.query with a raw query.
There's also a pull request that supports non default schemas in migration: https://github.com/sequelize/sequelize/pull/11274.
Ad
source: stackoverflow.com
Related Questions
- → Maximum call stack exceeded when instantiating class inside of a module
- → Browserify api: how to pass advanced option to script
- → Node.js Passing object from server.js to external modules?
- → gulp-rename makes copies, but does not replace
- → requiring RX.js in node.js
- → Remove an ObjectId from an array of objectId
- → Can not connect to Redis
- → React: How to publish page on server using React-starter-kit
- → Express - better pattern for passing data between middleware functions
- → Can't get plotly + node.js to stream data coming through POST requests
- → IsGenerator implementation
- → Async/Await not waiting
- → (Socket.io on nodejs) Updating div with mysql data stops without showing error
Ad