sequelize: Missing column "createdAt" when using "field" param with bulkCreate command
I have this error since upgrading to 3.0: ("sequelize": "^3.2.0"
to be precise)
{ [SequelizeDatabaseError: column "createdAt" of relation "store_table" does not exist]
name: 'SequelizeDatabaseError',
message: 'column "createdAt" of relation "store_table" does not exist',
parent:
{ [error: column "createdAt" of relation "store_table" does not exist]
name: 'error',
length: 124,
severity: 'ERROR',
code: '42703',
detail: undefined,
hint: undefined,
position: '59',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_target.c',
line: '923',
routine: 'checkInsertTargets',
And field is defined:
module.exports = function(sequelize) {
'use strict';
var DataTypes = require('sequelize');
return sequelize.define(
'store_table', {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
},
brandId: {
type: DataTypes.INTEGER,
field: 'brand_id',
references: 'brand',
referencesKey: 'id'
},
name: {
type: DataTypes.STRING,
allowNull: true,
validate: {
len: [1, 64]
}
},
address: {
type: DataTypes.TEXT,
allowNull: true,
validate: {
len: [1, 256]
}
},
createdAt: {
type: DataTypes.DATE,
field: 'created_at'
},
updatedAt: {
type: DataTypes.DATE,
field: 'updated_at'
}
}, {
freezeTableName: true
}
);
};
And present in the DB, obviously under the name of created_at
.
After reading this issue: https://github.com/sequelize/sequelize/issues/2641 I tried by adding underscored: true
flag and it does work as before.
The issue is only present on the bulkCreate
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 18 (2 by maintainers)
Here is the issue, bulkCreate doesn’t read the “field” property for the column definition and its trying to do an insert to a
createdAt
column while I have in the tablecreated_at
:This is completely new table that I created just to test the use case. The result is the same, with or without
timestamps: true
attribute.If I add
underscored: true
, then the SQL is correct and I see:However, when I do
Category.find
, I see double timestamps, take a look:This is the full definition of the Model:
I’m running sequelize 3.19.3. Still got this issue…