mysql - 无法添加或更新子行:外键约束失败 ON DELETE CASCADE ON UPDATE CASCADE
问题描述
当我在带有 mid、cid、ordertotal 的订单表中插入数据时遇到问题,然后它显示类似这样的错误无法添加或更新子行:外键约束失败 ( coindb
. orders
, CONSTRAINT orders_ibfk_1
FOREIGN KEY ( MID
) REFERENCES machine
( ID
) ON DELETE CASCADE ON UPDATE CASCADE)"。谁能帮我纠正这个问题
here is orders table
'use strict';
module.exports = (sequelize, DataTypes) => {
var Model = sequelize.define('orders', {
id: { type: DataTypes.INTEGER, field: 'id', primaryKey: true}
mid: { type: DataTypes.INTEGER, field: 'mid'},
cid: { type: DataTypes.INTEGER, field: 'cid'},
wid: { type: DataTypes.INTEGER, field: 'wid'},
oid: { type: DataTypes.INTEGER, field: 'oid'},
status: { type: DataTypes.CHAR, field: 'status'},
options: { type: DataTypes.STRING, field: 'options'},
starttime: { type: DataTypes.DATE,field: 'starttime'},
duration: { type: DataTypes.INTEGER, field: 'duration'},
ordertotal: { type: DataTypes.INTEGER, field: 'ordertotal'},
counter: { type: DataTypes.INTEGER, field: 'counter'},
closetime: { type: DataTypes.DATE, field: 'closetime'}
}, {
tableName: 'orders',
timestamps: false,
});
Model.prototype.toWeb = function (pw) {
let json = this.toJSON();
return json;
};
return Model;
};
and machine table
'use strict';
module.exports = (sequelize, DataTypes) => {
var Model = sequelize.define('machine', {
id:{type:DataTypes.INTEGER,field:'id',primaryKey:true,utoIncrement:true}
type : {type : DataTypes.STRING, field : 'type'},
bid : {type : DataTypes.INTEGER, field : 'bid'},
},
{
tableName: 'machine',
timestamps: false
});
Model.associate = function(models){
this.branches = this.belongsTo(models.branch, {foreignKey: 'bid'});
};
Model.prototype.toWeb = function (pw) {
let json = this.toJSON();
return json;
};
return Model;
};
解决方案
推荐阅读
- php - 如何使用 Lumen 在单个数据库中动态租户 ID
- typescript - 如何使用打字稿在角度 6 中显示每个 HTTP 请求和 HTTP 响应的数字微调器
- java - 如果线程获得了对象的锁怎么办
- javascript - Blazor 子菜单
- python - 将熊猫数据框附加到数据块中的现有表中
- reactjs - React 的焦点问题
- oracle - JMeter 5.2.1 - 连接属性被忽略
- servicestack - 带有 emitLowercaseUnderscoreNames = true 的 Servicestack JsConfig 不适用于具有字母数字名称的属性
- git - 如何获取最新创建的远程 Git 分支列表?
- go - 在 Couchbase 中插入只读文档