I generated the models of a MariaDB database by doing:
npx sequelize-auto -o "./models" -l es6 -d databaseName -h 127.0.0.1 -u 'user' -x 'pass'
The output of one of the models is as follows:
import _sequelize from 'sequelize';
const { Model, Sequelize } = _sequelize;
export default class Catalog extends Model {
static init(sequelize, DataTypes) {
super.init({
id: {
autoIncrement: true,
type: DataTypes.INTEGER.UNSIGNED,
allowNull: false,
primaryKey: true
},
name: {
type: DataTypes.TINYINT,
allowNull: true
},
comments: {
type: DataTypes.TEXT,
allowNull: true
},
origin: {
type: DataTypes.INTEGER.UNSIGNED,
allowNull: true,
references: {
model: 'Entities',
key: 'id'
}
}
}, {
sequelize,
tableName: 'Catalog',
timestamps: true,
indexes: [
{
name: "PRIMARY",
unique: true,
using: "BTREE",
fields: [
{ name: "id" },
]
},
{
name: "compositionPlace",
using: "BTREE",
fields: [
{ name: "compositionPlace" },
]
},
]
});
return Catalog;
}
}
The initModels.js
....
export default function initModels(sequelize) {
var Catalog = _Catalog.init(sequelize, DataTypes);
...
In my index.js I have:
import initModels from "./models/init-models.js";
var models = initModels(sequelize);
And I get this error:
/backend/node_modules/sequelize/lib/model.js:968
if (this.sequelize.isDefined(this.name)) {
^
TypeError: this.sequelize.isDefined is not a function
I can't import the modules because it seems that sequelize is looking for the model name but it is not finding it because it has been declared as a Class.
Any idea how to fix this?
Thanks