未看到播种数据库后所需的续集模型 属性
not seeing a sequelize model property that is required after seeding database
更新
下面有人建议为 shoutouts 添加模型 ID,我不再收到错误,但现在没有任何内容保存到我的数据库中?
添加以下新信息:
我在用户和 shoutouts 之间建立了一对多的关系。两个模型都有电子邮件 属性,
我正在尝试使用一种神奇的方法来设置 shoutout。当我使用 user.createShoutout()
我可以生成 shoutout,但是电子邮件 属性 没有出现在数据库中。
const Sequelize = require('sequelize')
const db = require('../db')
const Shoutout = db.define('shoutout', {
//NEW
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
}, //OLD
name: {
type: Sequelize.STRING,
validate: {
notEmpty: true
},
email: {
type: Sequelize.STRING,
unique: true,
allowNull: false
}
},
message: {
type: Sequelize.TEXT,
allowNull: false
},
from: {
type: Sequelize.STRING
}
})
module.exports = Shoutout
协会:
User.hasMany(Shoutouts)
Shoutouts.belongsTo(User)
User.hasMany(Emails)
Emails.belongsTo(User)
当我使用 user.AddShoutout()
如下:
let paramsObj = {
name: addEmail.firstName,
email:addEmail.email,
message: 'test msg',
userId: 3
}
//NEW
let id = 1;
const addInfo = await userThree.addShoutout(id,paramsObj)
//新
不再收到对象错误,实际上没有看到任何错误。但是当我查看我的 shoutouts table 时,没有添加任何内容。
当我 console.log 添加信息时
返回尝试创建 shoutout 的用户?
我需要帮助来尝试使用这个用户模型魔术方法来生成新的 shoutout!
感谢阅读本文以及任何建议!
您的电子邮件字段嵌套在姓名字段中
const Sequelize = require('sequelize')
const db = require('../db')
const Shoutout = db.define('shoutout', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
}, //OLD
name: {
type: Sequelize.STRING,
validate: {
notEmpty: true
},
email: { # <----------------------------- nested too deep
type: Sequelize.STRING,
unique: true,
allowNull: false
}
},
message: {
type: Sequelize.TEXT,
allowNull: false
},
from: {
type: Sequelize.STRING
}
})
module.exports = Shoutout
更新
下面有人建议为 shoutouts 添加模型 ID,我不再收到错误,但现在没有任何内容保存到我的数据库中? 添加以下新信息:
我在用户和 shoutouts 之间建立了一对多的关系。两个模型都有电子邮件 属性, 我正在尝试使用一种神奇的方法来设置 shoutout。当我使用 user.createShoutout() 我可以生成 shoutout,但是电子邮件 属性 没有出现在数据库中。
const Sequelize = require('sequelize')
const db = require('../db')
const Shoutout = db.define('shoutout', {
//NEW
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
}, //OLD
name: {
type: Sequelize.STRING,
validate: {
notEmpty: true
},
email: {
type: Sequelize.STRING,
unique: true,
allowNull: false
}
},
message: {
type: Sequelize.TEXT,
allowNull: false
},
from: {
type: Sequelize.STRING
}
})
module.exports = Shoutout
协会:
User.hasMany(Shoutouts)
Shoutouts.belongsTo(User)
User.hasMany(Emails)
Emails.belongsTo(User)
当我使用 user.AddShoutout() 如下:
let paramsObj = {
name: addEmail.firstName,
email:addEmail.email,
message: 'test msg',
userId: 3
}
//NEW
let id = 1;
const addInfo = await userThree.addShoutout(id,paramsObj)
//新
不再收到对象错误,实际上没有看到任何错误。但是当我查看我的 shoutouts table 时,没有添加任何内容。
当我 console.log 添加信息时 返回尝试创建 shoutout 的用户?
我需要帮助来尝试使用这个用户模型魔术方法来生成新的 shoutout!
感谢阅读本文以及任何建议!
您的电子邮件字段嵌套在姓名字段中
const Sequelize = require('sequelize')
const db = require('../db')
const Shoutout = db.define('shoutout', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
}, //OLD
name: {
type: Sequelize.STRING,
validate: {
notEmpty: true
},
email: { # <----------------------------- nested too deep
type: Sequelize.STRING,
unique: true,
allowNull: false
}
},
message: {
type: Sequelize.TEXT,
allowNull: false
},
from: {
type: Sequelize.STRING
}
})
module.exports = Shoutout