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)

Most upvoted comments

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 table created_at:

sql: 'INSERT INTO "category" ("id","name","createdAt","updatedAt") VALUES (DEFAULT,\'Arts, crafts, and collectibles\',\'2015-06-12 05:44:12.479 +00:00\',\'2015-06-12 05:44:12.479 +00:00\')

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:

Executing (default): INSERT INTO "category" ("id","name","created_at","updated_at")

However, when I do Category.find, I see double timestamps, take a look: screen shot 2015-06-12 at 07 48 58

This is the full definition of the Model:

module.exports = function(sequelize) {
  'use strict';

  var DataTypes = require('sequelize');

  return sequelize.define(
    'category', {
      id: {
        type: DataTypes.INTEGER,
        autoIncrement: true,
        primaryKey: true
      },

      name: {
        type: DataTypes.STRING,
        unique: true,
        allowNull: false,
        validate: {
          len: [1, 64]
        }
      },

      createdAt: {
        type: DataTypes.DATE,
        field: 'created_at'
      },

      updatedAt: {
        type: DataTypes.DATE,
        field: 'updated_at'
      }

    }, {
      timestamps: true,
      underscored: true,
      freezeTableName: true
    }
  );
};

I’m running sequelize 3.19.3. Still got this issue…