Error in migration to custom schema (PG)
Author: KolbaskinCreated Jul 7, 2021Updated Sep 23, 2026
Labelstype: bug
Issue Creation Checklist
[х] I have read the contribution guidelines
- Create custom schema in postgres database
- Add param "schema" into config file
- Create two migration files: one with creating a new table and second with adding extra column (both without specifying the schema name )
- Run "sequelize-cli db:migrate"
Config:
{
"development": {
"username": "user",
"password": "pass",
"database": "database",
"schema": "customschema",
"host": "localhost",
"dialect": "postgres",
"seederStorage": "sequelize",
"logging": false,
"seederStorageTableName": "sequelize_data"
}
}First migration:
"use strict";
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable("users", {
id: {
allowNull: false,
defaultValue: Sequelize.UUIDV4,
primaryKey: true,
type: Sequelize.UUID
},
name: {
type: Sequelize.STRING(100)
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable("users");
}
};Second:
"use strict";
module.exports = {
up: function(queryInterface, Sequelize) {
// logic for transforming into the new state
return queryInterface.addColumn("users", "realm", Sequelize.UUID);
},
down: function(queryInterface, Sequelize) {
// logic for reverting the changes
return queryInterface.removeColumn("users", "realm");
}
};Bug Description
The new table will created in the custom schema, but the new column sequelize will try add in schema "public"
What do you expect to happen?
I wanted see all objects in schema that is specified in the config.
What is actually happening?
The new table is in custom schema, but the new field is in public schema
Environment
- Sequelize version: 6.6.5
- Sequelize-cli version: 6.2.0
- Node.js version: 12
Bug Report Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s):
- I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don't know how to start, I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.
Source: sequelize/sequelize