Unable to start the server -

This is a template you can use to report issues. You can also drag images, videos and include Preformatted text

Expected behavior

The server should stay

Actual behavior

After running npm start - I get the following error

> usadmin@0.0.1 start /home/tharshan/Projects/uservitals/admin
> node ./server.js

Model creation error: Error: ARRAY is missing type definition for its values.
/home/tharshan/Projects/uservitals/admin/node_modules/sequelize/lib/associations/mixin.js:93
      throw new Error(`${source.name}.${_.lowerFirst(Type.name)} called with something that's not a subclass of Sequelize.Model`);
      ^


Error: changelogEntryToRoadmapItem.belongsTo called with something that's not a subclass of Sequelize.Model

Failure Logs

Please include any relevant log snippets, if necessary.

Context

Please provide any relevant information about your setup.

  • Package Version: latest
  • Express Version: latest
  • Sequelize Version: latest
  • Database Dialect: sql
  • Database Version: postgres 13.3

hi @viperfx,

Can you please describe the steps you follow to create your project?

The logged error relates a problem with changelogEntryToRoadmapItem model.
Can you please share it, with others models that are related to it?

Regards

Steps I took, are essentially what the create a new project guide showed me.

npm install -g forest-cli@latest -s
forest login
forest projects:create "uvadmin" --databaseConnectionURL ....

The above command ran fine and I got the following output at the end

  create app.js
  create docker-compose.yml
  create Dockerfile
  create package.json
  create server.js
√ Creating your project files
√ Hooray, installation success!
npm install -s
npm start
After running npm start, I got the following stack trace.

Model creation error: Error: ARRAY is missing type definition for its values.
D:\Projects\uvadmin\node_modules\sequelize\lib\associations\mixin.js:93
      throw new Error(`${source.name}.${_.lowerFirst(Type.name)} called with something that's not a subclass of Sequelize.Model`);
      ^

Error: changelogEntryToRoadmapItem.belongsTo called with something that's not a subclass of Sequelize.Model
    at Function.<anonymous> (D:\Projects\uvadmin\node_modules\sequelize\lib\associations\mixin.js:93:13)
    at Function.ChangelogEntryToRoadmapItem.associate (D:\Projects\uvadmin\models\changelog-entry-to-roadmap-item.js:23:33)
    at D:\Projects\uvadmin\models\index.js:30:19
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (D:\Projects\uvadmin\models\index.js:28:17)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (D:\Projects\uvadmin\routes\changelog-email-notification.js:3:40)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at D:\Projects\uvadmin\node_modules\require-all\index.js:56:46
    at Array.forEach (<anonymous>)
    at requireAll (D:\Projects\uvadmin\node_modules\require-all\index.js:34:9)
    at Object.<anonymous> (D:\Projects\uvadmin\app.js:56:1)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (D:\Projects\uvadmin\server.js:5:13)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)

Here is the changelogEntryToRoadmapItem

// This model was generated by Forest CLI. 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 ChangelogEntryToRoadmapItem = sequelize.define('changelogEntryToRoadmapItem', {
  }, {
    tableName: '_ChangelogEntryToRoadmapItem',
    timestamps: false,
    schema: process.env.DATABASE_SCHEMA,
  });
  ChangelogEntryToRoadmapItem.removeAttribute('id');
  // This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
  ChangelogEntryToRoadmapItem.associate = (models) => {
    ChangelogEntryToRoadmapItem.belongsTo(models.changelogEntry, {
      foreignKey: {
        name: 'aKey',
        field: 'A',
      },
      as: 'a',
    });
    ChangelogEntryToRoadmapItem.belongsTo(models.roadmapItem, {
      foreignKey: {
        name: 'bKey',
        field: 'B',
      },
      as: 'b',
    });
  };

  return ChangelogEntryToRoadmapItem;
};

This is changelogEntry

// This model was generated by Forest CLI. 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 ChangelogEntry = sequelize.define('changelogEntry', {

    id: {

      type: DataTypes.STRING,

      primaryKey: true,

      allowNull: false,

    },

    title: {

      type: DataTypes.STRING,

      allowNull: false,

    },

    slug: {

      type: DataTypes.STRING,

      allowNull: false,

    },

    desc: {

      type: DataTypes.STRING,

    },

    status: {

      type: DataTypes.ENUM(

        'DRAFT',

        'PUBLISHED',

        'SCHEDULED',

      ),

      defaultValue: Sequelize.literal('\'DRAFT\'::"ChangelogStatus"'),

      allowNull: false,

    },

    createdAt: {

      type: DataTypes.DATE,

      defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),

    },

    updatedAt: {

      type: DataTypes.DATE,

      defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),

    },

    publishAt: {

      type: DataTypes.DATE,

    },

    type: {

      type: DataTypes.ENUM(

        'FIX',

        'ANNOUCEMENT',

        'IMPROVEMENT',

        'NEW',

      ),

    },

    heroImage: {

      type: DataTypes.STRING,

    },

    number: {

      type: DataTypes.INTEGER,

      defaultValue: 0,

      allowNull: false,

    },

  }, {

    tableName: 'ChangelogEntry',

    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.

  ChangelogEntry.associate = (models) => {

    ChangelogEntry.belongsTo(models.user, {

      foreignKey: {

        name: 'createdByIdKey',

        field: 'createdById',

      },

      as: 'createdBy',

    });

    ChangelogEntry.belongsTo(models.membership, {

      foreignKey: {

        name: 'createdByMemberIdKey',

        field: 'createdByMemberId',

      },

      as: 'createdByMember',

    });

    ChangelogEntry.belongsTo(models.team, {

      foreignKey: {

        name: 'teamIdKey',

        field: 'teamId',

      },

      as: 'team',

    });

    ChangelogEntry.belongsToMany(models.roadmapItem, {

      through: 'changelogEntryToRoadmapItem',

      foreignKey: 'A',

      otherKey: 'B',

      as: 'roadmapItemThroughChangelogEntryToRoadmapItems',

    });

    ChangelogEntry.belongsToMany(models.emailPreference, {

      through: 'changelogEmailNotification',

      foreignKey: 'changelogEntryId',

      otherKey: 'prefId',

      as: 'emailPreferenceThroughChangelogEmailNotifications',

    });

    ChangelogEntry.hasMany(models.changelogEntryLabel, {

      foreignKey: {

        name: 'changelogEntryIdKey',

        field: 'changelogEntryId',

      },

      as: 'changelogEntryChangelogEntryLabels',

    });

  };

  return ChangelogEntry;

};

There are many other models - but not sure it makes sense to share them all on this public forum. I can DM you the project files - if you let me know how I can share it securely for your internal team only.

Also, is there a workaround for this issue?

For example, Is there a command I can use to specify exactly which models I want imported after the analysis. So that way I can include the most important models and see which ones break.

Hi there - could I get this reviewed please? I’ve not been able to use the software due to this issue.

Hi @viperfx, and sorry for the late answer,

You can exclude some models by following this doc.

Can you please share the SQL script which creates the tables ChangelogEntryToRoadmapItem and changelogEntry ? I will need to reproduce this generation failure.
Also, can you please specify which specific version you used (‘latest’ is not precise enough as it may change recently)

Bets regards

Where do I find the SQL script?

And will update the post with the version numbers.

The preferred way would be to use pg_dump.

Alternative 1: Figure you are using Postico as database client, when you selected the table, you can find the DDL / Structure menu which will display you the SQL script.

Alternative 2: If you are using datagrip as satabase client, when you are on the table list, right click on the table, then select “SQL Script / generate DDL”.

If you are using another tool, check its documentation.

OK I have uploaded the SQL scripts to github - Forrest SQL (github.com)

The version I am using is forest-cli/2.3.0 win32-x64 node-v14.17.6

Also I have tried to use the excludeModels option - but when I run npm start I can see from the stack trace it walks through the same files. Therefore the error happens.

It seems I have to go and manually comment out lines for each model file?

Is there a way to specify which models to generate at project creation?

Hi,

Thank you.
I’ve generated a server using the SQL script you provided and I was not able to reproduce the issue, the generation performs fine.

But to have the script working, I dropped relations to tables that are missing from the script.
The list of dropped elements are the following:

  • _ChangelogEntryToRoadmapItem reference to RoadmapItem
  • ChangelogEntry reference to Membership
  • ChangelogEntry reference to Team
  • ChangelogEntry reference to User
  • ChangelogEntry type field
  • ChangelogEntry status field

Since the problem is related to a changelogEntryToRoadmapItem.belongsTo it can be on ChangelogEntry or RoadmapItem. The problem should be on RoadmapItem because ChangelogEntry is working on my side. Since I don’t have RoadmapItemscript I can’t check it.

Is this model well generated on your side?

If you need further investigations, please share the entire SQL.

Regards

I sent you a private message with the full zip file of the code.

Hey @viperfx :wave:

Could you also send this to me as DM? @Sliman_Medini is currently off, and I’ll take care of your issue :pray:

Ive added you to the DM.

Hey, I wanted to follow up on this.

@jeffladiray you mentioned this in DM:

Looks like your roadmap-item.js contains

type: DataTypes.ARRAY(DataTypes.null),

Which is most likely the source of the issue here


Any suggestions on whats wrong here?

Hey @viperfx

Both the

&

type: DataTypes.ARRAY(DataTypes.null),

leads me to think that your server should start by replacing

DataTypes.null by the corresponding datatype of the array items you are saving.

Let me know if that helps