sequelize-auto icon indicating copy to clipboard operation
sequelize-auto copied to clipboard

How to initialize models.

Open dograshvili opened this issue 1 year ago • 0 comments

Hello guys. It's the first time I use sequelize-auto with Typescript and I facing a bit of a problem. I am using sequelize-auto with the following flags -l ts -o my/folder/path/ --dialect postgres --cm c (with other flags as well to connect to the database). The model files are generated successfully. Now when I try to initiate the models as the documentation says in the Typescript section using the initModels function which is exported in the init-models.ts file and I get the following error:

Argument of type 'Sequelize<PostgresDialect>' is not assignable to parameter of type 'Sequelize'.
  Type 'Sequelize<PostgresDialect>' is missing the following properties from type 'Sequelize': config, beforeInit, afterInit, set, and 4 more.ts(2345)

Here is the code that I use to create the Sequelize instance and to initiate the models

import { Sequelize } from '@sequelize/core';
import { initModels } from 'models/init-models';

const sequelize = new Sequelize({
  dialect: PostgresDialect,
  database: envVars.dbDatabase,
  schema: envVars.dbSchema,
  user: envVars.dbUser,
  password: envVars.dbPassword,
  host: envVars.dbHost,
  port: envVars.dbPort,
  ssl: true
});

initModels(sequelize);

dograshvili avatar Aug 08 '24 19:08 dograshvili