gpt4 book ai didi

node.js - Sequelize : throw new Error (`${this.name}.belongsToMany called with something that' s not a subclass of Sequelize. 模型

转载 作者:行者123 更新时间:2023-12-03 22:19:25 30 4
gpt4 key购买 nike

在我的程序中:
电影.js

import  { DataTypes } from 'sequelize'
import Actor from './actor'
import ActorMovies from './actormovies'
import { sequelize } from '../../db/seq'

const Movie = sequelize.define('Movie', { name: DataTypes.STRING });
Movie.belongsToMany(Actor, { through: ActorMovies });

export default Movie
Actor .js
import { DataTypes } from 'sequelize'
import Movie from './movie'
import ActorMovies from './actormovies'
import { sequelize } from '../../db/seq'

const Actor = sequelize.define('Actor', { name: DataTypes.STRING });
Actor.belongsToMany(Movie, { through: ActorMovies });

export default Actor
Actor 电影.js
import { DataTypes } from 'sequelize'
import Movie from './movie'
import Actor from './actor'
import { sequelize } from '../../db/seq'

const ActorMovies = sequelize.define('ActorMovies', {
MovieId: {
type: DataTypes.INTEGER,
references: {
model: Movie,
key: 'id'
}
},
ActorId: {
type: DataTypes.INTEGER,
references: {
model: Actor,
key: 'id'
}
}
});

export default ActorMovies
它会抛出一个错误
throw new Error(`${this.name}.belongsToMany called with something that's not a subclass of Sequelize.Model
我想它可能在 movie.js 和 actor.js 中使用了不同的 Sequelize ,但我不确定。
有人已经看到类似的错误了吗?我搜索了几天没有任何合适的问题,如果有人可以帮助我真的很感激,
感谢 !

最佳答案

那是因为您试图在他们自己的文件中使用 .belongsToMany。
简单说明:当您需要其中一个模型文件时,其中之一尚未定义为 Sequelize 模型。
尝试将 index.js 文件用于您的模型文件夹。 Take a look at my answer there
您可以阅读@Dorian Jakov Stern Vukotic answer

关于node.js - Sequelize : throw new Error (`${this.name}.belongsToMany called with something that' s not a subclass of Sequelize. 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62897998/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com