你好,我是NodeJs的新用户,我在自己的NodeJs项目中集成了Sequelize库,并定义了我的模型。当我添加模型的关系时,会出现以下错误
引发新的错误(
${source.name}.${_.lowerFirst(Type.name)} called with something that's not a subclass of Sequelize.Model
);^错误:user_posts_boxes.belongsTo用非Sequelize.Model的子类在功能。 (/home/rizwan/php/nodejs/node_modules/sequelize/lib/associations/mixin.js:93:13)我的帖子模型
const Sequelize = require('sequelize');
module.exports = function (sequelize) {
var Post = sequelize.define('user_posts', {
}, {timestamp: false});
return Post;
};
我的邮箱模型
const Sequelize = require('sequelize');
var Post = require('./Post');
module.exports = function (sequelize) {
var PostBox = sequelize.define('user_posts_boxes', {
}, {timestamp: false});
PostBox.belongsTo(Post, {foreignKey: 'user_pots_id'});
return PostBox;
};
研究期间,我从以下链接中找到了帮助hasMany called with something that's not an instance of Sequelize.Model
建议我使用全部方法和参考链接
您尚未在PostBox
模型中定义任何列。尝试:
const Sequelize = require('sequelize');
var Post = require('./Post');
module.exports = function (sequelize) {
var PostBox = sequelize.define('user_posts_boxes',
{
post_id: {
type: Sequelize.INTEGER,
references: {
model: Post,
key: "post_id" // this is the `posts.post_id` column - name it according to your posts table definition (the one defined in ./Post)
}
}
}, {timestamp: false});
PostBox.belongsTo(Post, {foreignKey: 'post_id'});
return PostBox;
};