Filippo1980 Filippo1980 - 11 months ago 146
Node.js Question

Node.js, sequelize and Unknown column

I read this similar question:
Sequelize Unknown column '*.createdAt' in 'field list'

but the solution doesn't work for me!
This is my code:

var User = sequelize.define("User", {
id: {
type: DataTypes.UUID,
primaryKey: true
cognome: DataTypes.STRING,
nome: DataTypes.STRING,
email: DataTypes.STRING,
password: DataTypes.TEXT,
stato: DataTypes.INTEGER,
ruolo: DataTypes.INTEGER
}, {
freezeTableName: true
}, {
timestamps: false

the error is:

Executing (default): SELECT `id`, `cognome`, `nome`, `email`, `data_nascita`, `password`, `cellulare`, `stato`, `blacklist`, `createdAt`, `updatedAt` FROM `Candidato` AS `Candidato`;
Unhandled rejection SequelizeDatabaseError: ER_BAD_FIELD_ERROR: Unknown column 'createdAt' in 'field list'

Answer Source

Instead of passing { timestamps: false } as an additional param of Sequelize.define call, you should extend the existing (third) one with the corresponding property:

var User = sequelize.define("User", {
  // model definition skipped
}, { 
    freezeTableName: true,
    timestamps: false

... as it described in the docs.