0

I am building a new NodeJS application with MySQL. I need to use the existing database from the original version of the application. I am using a mysql dump file from the old database to create the new database.

I generated the models automatically based on the existing database using sequelize-auto module.

The createdAt field does not exist in the database and timestamps are specifically disabled in all of the models. However, I am still seeing this error when running a query such as models.people.findAll() or models.people.findOne():

"SequelizeDatabaseError: Unknown column 'createdAt' in 'field list'"

I followed the instructions in this other post to disable timestamps globally, however it does not work to solve the issue.

Sequelize Unknown column '*.createdAt' in 'field list'

Here are the relevant versions:

"mysql": "^2.17.1",
"mysql2": "^1.6.5",
"sequelize": "^5.8.5",
"sequelize-auto": "^0.4.29",
"sequelize-auto-migrations": "^1.0.3"

Here is the people model. Timestamps have been disabled explicitly in this and all other models globally. Also, I have read that timestamps : false is the default in the latest version of sequelize, so I am confused as to how this is an issue at all.

module.exports = function(sequelize, DataTypes) {
  return sequelize.define('people', {
    PersonID: {
      type: DataTypes.INTEGER(10).UNSIGNED,
      allowNull: false,
      primaryKey: true
    },
    FirstName: {
      type: DataTypes.STRING(50),
      allowNull: false
    },
    LastName: {
      type: DataTypes.STRING(50),
      allowNull: false
    },
    Username: {
      type: DataTypes.STRING(50),
      allowNull: true
    },
    EmailAddress: {
      type: DataTypes.STRING(255),
      allowNull: true
    }
  }, {
    tableName: 'people',
    timestamps: 'false'
  });
};
pengz
  • 2,279
  • 3
  • 48
  • 91

1 Answers1

2

I see that you use sequelize-auto-migrations in your dependencies and I found an opened issue in their repo linked to your problem.

You maybe made a mistake setting the timestamps or the migrations are executed in the server after the disabling of the timestamps so the created_at columns are being added again to your tables.

I hope this helps you.

F.Chedd
  • 56
  • 3
  • 2
    Thank you! I took another look at the configuration and I just had to simply change the string 'false' to a boolean. timestamps: false – pengz May 22 '19 at 20:13