'SequelizeDatabaseError: column User.last_sign_in_at does not exist. Column shows up in PGAdmin

I have recently tried to add the column "last_sign_in_at" to the User table (named "UsersTable" in our db) using sequelize. I've created the migration file and run the migration:

module.exports = {
  async up (queryInterface, Sequelize) {
    return queryInterface.addColumn('UsersTable', 'last_sign_in_at', {
      type: Sequelize.DATE,
    });
  },

  async down (queryInterface, Sequelize) {
    return queryInterface.removeColumn('UsersTable', 'last_sign_in_at');
  }
};

I have updated the User model in Node.js:

module.exports = (sequelize, DataTypes) => {
    let User = sequelize.define(
        'User',
        {
            firstName: DataTypes.STRING,
            middleName: DataTypes.STRING,
            lastName: DataTypes.STRING,
            verificationKey: DataTypes.STRING,
            verifiedDate: DataTypes.DATE,
            LocationId: DataTypes.INTEGER,
...

            gender: DataTypes.INTEGER,
            ethnicity: DataTypes.INTEGER,
            metro_location_id: DataTypes.INTEGER,
            newToSalesType: {
                type: DataTypes.INTEGER,
                field: 'new_to_sales_type_id',
            },
            newToSalesStatus: {
                type: DataTypes.INTEGER,
                field: 'new_to_sales_status_id',
            },
            countryId: {
                type: DataTypes.INTEGER,
                field: 'country_id',
            },
            lastSignInAt: {
                type: DataTypes.DATE,
                field: 'last_sign_in_at',
            }
        },

I have a route that is supposed to update this value every time a user logs in and is authenticated:

router.authenticate = (req, res, next) => {
    passport.authenticate('local', function (err, user, info) {
        if (err) {
            return set403Response(res);
        }
        if (!user) {
            models.User.findAll({
                where: {
                    email: {$ilike: req.body.email}
                }
            }).then(users => {
                if (users.length > 0) {
                    if (!users[0].dataValues.isLinkedinLogin && !users[0].dataValues.isFacebookLogin) {
                        return set403Response(res, {emailExists: true});
                    }
                }

                return set403Response(res);
            });
        } else {
            req.logIn(user, function (err) {
                if (err) {
                    return set403Response(res);
                }
                models.UserLogin.write(user);
                models.User.update(
                    { lastSignInAt: Date.now() },
                    { where: { user_id: user.user_id } }
                ).then(()=>{
                    console.log('TRACE 3')
                    return res.redirect('/api/currentUser');
                })
            });
        }
    })(req, res, next);
}

The field is showing up in PGAdmin:

last_sign_in_at in the db

I'm even able to make a SQL query to update the value of last_sign_in_at in my Query Tool for individual rows.

HOWEVER! When I try to log in a user in my app, my server is telling me:

SequelizeDatabaseError: column User.last_sign_in_at does not exist

I'm completely stumped.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source