I have a simple migration that renames a column. The migration file looks like this:
const tableName= 'aTable';
module.exports = {
up: async (queryInterface, Sequelize) => {
queryInterface.renameColumn(tableName, 'oldName', 'newName');
},
down: async (queryInterface, Sequelize) => {
queryInterface.renameColumn(tableName, 'newName', 'oldName');
},
};
When I apply the migration, I get the following output:
== migrateFile: migrating =======
== migrateFile: migrated (0.071s)
Then when I use the model, I get the following error:
name: 'SequelizeDatabaseError',
parent: error: column aTable.newName does not exist
If I print out the columns, I see the oldName is still in the table. Other migrations seem to work.
The database is postgres. I'm starting to take a look at the logs to see if I can find anything.
Is there any way I can debug sequelize to figure out what is going on? Does anyone have any ideas as to what could be causing this problem?
You simply forgot to wait for the result of renaming query, just add await
and that's it:
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.renameColumn(tableName, 'oldName', 'newName');
},
down: async (queryInterface, Sequelize) => {
await queryInterface.renameColumn(tableName, 'newName', 'oldName');
},
};