Model undefined

Feature(s) impacted

create a new record in a table.

Observed behavior

I added recently a new model, after command forest schema:update, the model file is added to models/ directory…

Then, I have this line to create record on cMailsLog table:
(file: routes/contact.js)

const models = require("../models");
          await models.cMailsLog.create({
            emailFrom: "mail..",
            emailTo: email,
            emailId: type,
            emailVars: JSON.stringify({
              fullname: user.nom,
              tutee_last_name: user.nom,
              hunter: user.hunter,
            emailStatus: "OK",

Expected behavior

create new record.

Failure Logs

the log of {models} show all models but not the cMailsLog.
and :

(node:19) UnhandledPromiseRejectionWarning: TypeError: Cannot read property ‘create’ of undefined
at /usr/src/app/routes/contacts.js:924:34
at processTicksAndRejections (internal/process/task_queues.js:95:5)

model file :

// This model was generated by Forest CLI. However, you remain in control of your models.
// Learn how here:
module.exports = (sequelize, DataTypes) => {
  const { Sequelize } = sequelize;
  // This section contains the fields of your model, mapped to your table's columns.
  // Learn more here:
  const CMailsLog = sequelize.define('cMailsLog', {
    emailFrom: {
      type: DataTypes.STRING,
    id: {
      type: DataTypes.BIGINT,
      defaultValue: Sequelize.literal('nextval(\'c_mails_log_id_seq\'::regclass)'),
      allowNull: false,
    emailTo: {
      type: DataTypes.STRING,
    templateId: {
      type: DataTypes.STRING,
    emailId: {
      type: DataTypes.STRING,
    emailVars: {
      type: DataTypes.STRING,
    dateSent: {
      type: DataTypes.DATE,
      defaultValue: Sequelize.literal('now()'),
    emailStatus: {
      type: DataTypes.STRING,
    receiverId: {
      type: DataTypes.INTEGER,
  }, {
    tableName: 'c_mails_log',
    underscored: true,
    timestamps: false,
    schema: process.env.DATABASE_SCHEMA,

  // This section contains the relationships for this model. See:
  CMailsLog.associate = (models) => {

  return CMailsLog;

  • Project name: Clevermate
  • Agent technology: nodejs
  • Agent (forest package) name & version: “forest-express-sequelize”: “9.3.5”,
  • Database type: postgres
1 Like

Hi @Adel_de_Clevermate ,

In the nodejs agent, you will not need to use the CLI to update your schema but restart your agent.
I do not see your new collection in our schema.
First of all, could you please relaunch your agent and verify that you have access to it in your project ?

Best regards,


Hi @shohanr

Thank you for your response.
I restarted the server (and rebuild the docker image) and it is fixed now.

1 Like