sequelize migrations not running

Question

I'm having a weird issue with Sequelize I haven't encountered before, when I try to run my migrations nothing happens. I get the following output:

Loaded configuration file "config/config.json"
Using environment "development"

And the program just exits back.

I've checked my code multiple times over and everything checks out.

Model code:

module.exports = {
up: (queryInterface, Sequelize) => {
    return queryInterface.createTable("users", {
        id: {
            allowNull: false,
            autoIncrement: true,
            primaryKey: true,
            type: Sequelize.INTEGER
        },
        username: {
            type: Sequelize.STRING,
            unique: true,
            allowNull: false,
            validate: {
                notEmpty: true
            }
        },
        email: {
            type: Sequelize.STRING,
            unique: true,
            allowNull: false,
            validate: {
                notEmpty: true,
                isEmail: true
            }
        },
        password: {
            type: Sequelize.STRING,
            allowNull: false,
            validate: {
                notEmpty: true,
                len: [7, 42]
            }
        },
        createdAt: {
            type: Sequelize.DATE
        },
        updatedAt: {
            type: Sequelize.DATE
        }
    })
},
down: (queryInterface, Sequelize) => {
    return queryInterface.dropTable("users")
}
}

And here is a snippet from my model/index.js:

const fs = require("fs")
const path = require("path")
const Sequelize = require("sequelize")

const basename = path.basename(__filename)
const env = process.env.TEST_ENV || "development"
const config = require(`${__dirname}/../config/config.js`)[env]
const db = {}

console.log('config', config)

let sequelize
if (config.use_env_variable) {
    sequelize = new Sequelize(process.env[config.use_env_variable], config)
} else {
    sequelize = new Sequelize(
        config.database,
        config.username,
        config.password,
        config
    )
}

It's almost like sequelize just isn't picking up any of migrations file. I'm not sure how I should troubleshoot this. Any help on this would be much appreciated.

Answer

I ran into this issue as well after updating my node version from 12.16.2 to 14.15.4, suddenly the migrations stopped working with no error message being displayed. To fix this, simply run:

npm install pg@latest

According to pg's documentation, to use node version >= 14.x you will need to install pg@8.2.x or later due to some internal stream changes on the node 14 branch.

For further reading, look at pg's official documentation here.

This answer was originally posted on Stack Overflow. You can find the full discussion here.

Related Posts

Transfer git repositories from GitLab to GitHub - can we, how to and pitfalls (if any)?

## Question Can one transfer repositories from GitLab to GitHub if the need be. If so, how exactly can I go about doing the same? Also, are there any pitfalls in doing so or precautionary measures

Read More

Cannot set headers after they are sent to the client - error

## Question Error `[ERR_HTTP_HEADERS_SENT]`: Cannot set headers after they are sent to the client ```text `at ServerResponse.setHeader (_http_outgoing.js:558:11) at ServerResponse.header (D:\D

Read More

Pulling data with 'Where' and 'Include' statements at the same time

## Question I have managed to get my include statements working with my foreign keys however when I try to add a 'where' statement to the findAll statement I am getting the below error. I have check

Read More