sequelize-typescript
sequelize-typescript copied to clipboard
sequelize.addModels(...) is not a functio
mysql.ts
import {Sequelize, Table, Column, Model } from 'sequelize-typescript'
@Table
export class Person extends Model<Person> {
@Column
get name(): string {return this.getDataValue('name');};
set name(value: string) {
this.setDataValue('name', value);
}
@Column
get birthday(): Date {return this.getDataValue('birthday');};
set birthday(value: Date) {
this.setDataValue('birthday', value);
}
}
const sequelize = new Sequelize({
database: "test",
username: "root",
password: "M7yfl^4J@9ZCQzOi",
host: '47.104.232.60',
port: 2023,
dialect: 'mysql',
});
sequelize.addModels([Person])
(async () => {
await Person.create({
name: "jason",
birthday: new Date(),
})
})
PS > ts-node .\mysql.ts
ERROR:
E:\workspace\node\project\test\mysql.ts:31
sequelize.addModels([Person])
^
TypeError: sequelize.addModels(...) is not a function
at Object.<anonymous> (E:\workspace\node\project\test\mysql.ts:31:30)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
at Module.m._compile (C:\Users\Administrator\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:1043:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Object.require.extensions.<computed> [as .ts] (C:\Users\Administrator\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:1046:12)
at Module.load (internal/modules/cjs/loader.js:879:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at main (C:\Users\Administrator\AppData\Roaming\npm\node_modules\ts-node\src\bin.ts:225:14)
at Object.<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modules\ts-node\src\bin.ts:512:3)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Module.load (internal/modules/cjs/loader.js:879:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47
npm list
[email protected] [email protected] [email protected] [email protected] @types/[email protected] @types/[email protected] @types/[email protected]
Does this issue is resolved? I also have the same problem.
Also having this issue.
Oh, I was importing "sequelize" instead of "sequelize-typescript"
yes i resolved this issue by importing sequelize-typescript