Urgent! Cant add data to database from UI

I just connected to the DB, tried creating my first row from the admin panel.

Expected behavior

It gets saved with no error

Actual behavior

creation failed: invalid input syntax for type timestamp: "Invalid date" This happens even when I put deleted at the date to make sure it is not empty:

Failure Logs

Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments:
[0] _isAMomentObject: true, _isUTC: false, _useUTC: false, _l: undefined, _i: CURRENT_TIMESTAMP, _f: undefined, _strict: undefined, _locale: [object Object]
Error
at Function.createFromInputFallback (/Users/bk/server-admin/node_modules/sequelize/node_modules/moment/moment.js:319:25)
at configFromString (/Users/bk/server-admin/node_modules/sequelize/node_modules/moment/moment.js:2536:19)
at configFromInput (/Users/bk/server-admin/node_modules/sequelize/node_modules/moment/moment.js:2978:13)
at prepareConfig (/Users/bk/server-admin/node_modules/sequelize/node_modules/moment/moment.js:2961:13)
at createFromConfig (/Users/bk/server-admin/node_modules/sequelize/node_modules/moment/moment.js:2928:44)
at createLocalOrUTC (/Users/bk/server-admin/node_modules/sequelize/node_modules/moment/moment.js:3022:16)
at createLocal (/Users/bk/server-admin/node_modules/sequelize/node_modules/moment/moment.js:3026:16)
at hooks (/Users/bk/server-admin/node_modules/sequelize/node_modules/moment/moment.js:16:29)
at DATE._applyTimezone (/Users/bk/server-admin/node_modules/sequelize/lib/data-types.js:460:21)
at DATE._stringify (/Users/bk/server-admin/node_modules/sequelize/lib/data-types.js:465:17)
at DATE._stringify (/Users/bk/server-admin/node_modules/sequelize/lib/dialects/postgres/data-types.js:175:20)
at DATE.stringify (/Users/bk/server-admin/node_modules/sequelize/lib/data-types.js:23:19)
at DATE.bindParam (/Users/bk/server-admin/node_modules/sequelize/lib/data-types.js:31:35)
at PostgresQueryGenerator.format (/Users/bk/server-admin/node_modules/sequelize/lib/dialects/abstract/query-generator.js:1011:29)
at PostgresQueryGenerator.insertQuery (/Users/bk/server-admin/node_modules/sequelize/lib/dialects/abstract/query-generator.js:201:30)
at QueryInterface.insert (/Users/bk/server-admin/node_modules/sequelize/lib/query-interface.js:880:37)
at Promise.try.then.then.then (/Users/bk/server-admin/node_modules/sequelize/lib/model.js:3985:52)
at tryCatcher (/Users/bk/server-admin/node_modules/sequelize/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/bk/server-admin/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/Users/bk/server-admin/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/Users/bk/server-admin/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/Users/bk/server-admin/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:729:18)
at _drainQueueStep (/Users/bk/server-admin/node_modules/sequelize/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/Users/bk/server-admin/node_modules/sequelize/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/Users/bk/server-admin/node_modules/sequelize/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (/Users/bk/server-admin/node_modules/sequelize/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (internal/timers.js:443:21)
[forest] :deciduous_tree::deciduous_tree::deciduous_tree: Unexpected error: invalid input syntax for type timestamp: “Invalid date”
SequelizeDatabaseError: invalid input syntax for type timestamp: “Invalid date”
at Query.formatError (/Users/bk/server-admin/node_modules/sequelize/lib/dialects/postgres/query.js:354:16)
at query.catch.err (/Users/bk/server-admin/node_modules/sequelize/lib/dialects/postgres/query.js:71:18)
at tryCatcher (/Users/bk/server-admin/node_modules/sequelize/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/bk/server-admin/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/Users/bk/server-admin/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/Users/bk/server-admin/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/Users/bk/server-admin/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:725:18)
at _drainQueueStep (/Users/bk/server-admin/node_modules/sequelize/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/Users/bk/server-admin/node_modules/sequelize/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/Users/bk/server-admin/node_modules/sequelize/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (/Users/bk/server-admin/node_modules/sequelize/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (internal/timers.js:443:21)
POST /forest/divisionOutlines 500 96 - 141.730 ms

Context

Please provide any relevant information about your setup.

  • Package Version:

  • Express Version:
    “chalk”: “~1.1.3”,
    “cookie-parser”: “1.4.4”,
    “cors”: “2.8.5”,
    “debug”: “~4.0.1”,
    “dotenv”: “~6.1.0”,
    “express”: “~4.16.3”,
    “express-jwt”: “5.3.1”,
    “forest-express-sequelize”: “^6.0.0”,
    “morgan”: “1.9.1”,
    “require-all”: “^3.0.0”,
    “sequelize”: “~5.15.1”,
    “pg”: “~8.2.2”

  • Sequelize Version:

  • Database Dialect:

  • Database Version:

  • Project Name: server-admin

Hi @BK42 :wave: thank your for your feedback.
To understand more easily your issue you faced of, can you provide me the definition of your Divison Outine model please.

Hi @Arnaud_Moncel ,

Thank you for looking into it.

Following is the schema i have in place. I could be 100% wrong, but i suspect there might be a bug in CURRENT_TIMESTAMP being not formatted in a way that could be understood by postgres.`

CREATE TABLE IF NOT EXISTS division_outlines(
    id serial PRIMARY KEY,
    created_at timestamp default current_timestamp,
    updated_at timestamp default current_timestamp,
    deleted_at timestamp,

    name VARCHAR (50) UNIQUE NOT NULL,
    ao_involvement VARCHAR (50) NOT NULL,
    description VARCHAR (255)
);

CREATE TABLE IF NOT EXISTS function_outlines(
    id serial PRIMARY KEY,
    created_at timestamp default current_timestamp,
    updated_at timestamp default current_timestamp,
    deleted_at timestamp,

    name VARCHAR (50) UNIQUE NOT NULL,
    folder VARCHAR (50)
);

CREATE TABLE function_outlines_division_outlines (
    function_outline_id int REFERENCES function_outlines (id) ON UPDATE CASCADE,
    division_outline_id int REFERENCES division_outlines (id) ON UPDATE CASCADE,
    CONSTRAINT function_outlines_division_outlines_pkey PRIMARY KEY (function_outline_id, division_outline_id)
);

Hi @bk42

It is probably an issue with the model related to this table.
Could you please share with us the content of your generated /models/division_outlines.js model?

Thanks for your help.

See model below, should ‘CURRENT_TIMESTAMP’ be actual JS date object/UNIX timestamp?

// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
module.exports = (sequelize, DataTypes) => {
  const { Sequelize } = sequelize;
  // This section contains the fields of your model, mapped to your table's columns.
  // Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
  const DivisionOutlines = sequelize.define('divisionOutlines', {
    createdAt: {
      type: DataTypes.DATE,
      defaultValue: "CURRENT_TIMESTAMP",
    },
    updatedAt: {
      type: DataTypes.DATE,
      defaultValue: "CURRENT_TIMESTAMP",
    },
    deletedAt: {
      type: DataTypes.DATE,
    },
    name: {
      type: DataTypes.STRING,
    },
    aoInvolvement: {
      type: DataTypes.STRING,
    },
    description: {
      type: DataTypes.STRING,
    },
  }, {
    tableName: 'division_outlines',
    underscored: true,
    schema: process.env.DATABASE_SCHEMA,
  });

  // This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
  DivisionOutlines.associate = (models) => {
    DivisionOutlines.belongsToMany(models.functionOutlines, {
      through: 'functionOutlinesDivisionOutlines',
      foreignKey: 'division_outline_id',
      otherKey: 'function_outline_id',
    });
  };

  return DivisionOutlines;
};

Hi @BK42 :wave:t3:

The fix below should get you going, can you please apply it to your different models where you have the createdAt and updatedAt fields?

// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
module.exports = (sequelize, DataTypes) => {
  const { Sequelize } = sequelize;
  // This section contains the fields of your model, mapped to your table's columns.
  // Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
  const DivisionOutlines = sequelize.define('divisionOutlines', {
    createdAt: {
      type: DataTypes.DATE,
      defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
    },
    updatedAt: {
      type: DataTypes.DATE,
      defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
    },
    deletedAt: {
      type: DataTypes.DATE,
    },
    name: {
      type: DataTypes.STRING,
    },
    aoInvolvement: {
      type: DataTypes.STRING,
    },
    description: {
      type: DataTypes.STRING,
    },
  }, {
    tableName: 'division_outlines',
    underscored: true,
    schema: process.env.DATABASE_SCHEMA,
  });

  // This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
  DivisionOutlines.associate = (models) => {
    DivisionOutlines.belongsToMany(models.functionOutlines, {
      through: 'functionOutlinesDivisionOutlines',
      foreignKey: 'division_outline_id',
      otherKey: 'function_outline_id',
    });
  };

  return DivisionOutlines;
};

We will look into what went wrong during the models generation and keep you posted.

Let us know if you need anything else :slightly_smiling_face:

1 Like

Hi @ziad,

That did the trick, ForestAdmin community is the best :raised_hands:

Thanks a tonne!
-BK

1 Like

Did we fix anything at the model generation level to address this? I think my lumber is still generating models defaultValue: "CURRENT_TIMESTAMP"