javascript - 您如何正确更改续集中的模型?
问题描述
我有以下两个模型,并试图将 Report 模型上的 userId 属性更改为不必是唯一的。models.Report.create({ userId: 1 })
当我将 unique 更改为 false 或完全删除该属性时,在尝试使用现有 userId 创建报告时(当 1 是现有用户的 id 时使用)时,我仍然收到唯一验证错误。我也尝试过进行迁移并运行它无济于事。
我在这里错过了什么吗?一直坚持这一点,因此非常感谢任何输入。谢谢你。
报告.js
module.exports = (sequelize, DataTypes) => {
const Report = sequelize.define(
'Report',
userId: {
allowNull: false,
type: Sequelize.INTEGER,
unique: true,
},
);
Report.associate = function(models) {
Report.belongsTo(models.UserInfo, { foreignKey: 'userId' });
};
return Report;
};
用户信息.js
module.exports = (sequelize, DataTypes) => {
const UserInfo = sequelize.define(
'UserInfo',
{
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
);
UserInfo.associate = function associate(models) {
ApplicantInfo.hasMany(models.Report, { foreignKey: 'applicantId' });
};
return ApplicantInfo;
};
解决方案
推荐阅读
- java - React Native 集成到现有的 android 项目
- ios - 如何在数组内搜索并返回所有搜索到的数据
- primefaces-datatable - Primefaces 数据表限制重新排序
- asp.net - Swagger:POST 和 PUT 在同一控制器中时无法加载 API 定义(Web Api 核心)
- r - 在 R 中,结合单个字数和字典字数
- python - AttributeError:无法获取属性“data_samples”
- vb.net - 当我只更新 1 条记录 MS Access 时,所有记录都已更新
- r - 在 dplyr/ggplot2 中使用因子与字符和整数与双列
- java - Spring Boot 和 Thymeleaf 的标头数据的控制器问题
- sqlite - 如何使用sqlite中的当前日期时间更新现有表的日期时间列