Javascript onDelete:';级联';不删除子行
这是作者表Javascript onDelete:';级联';不删除子行,javascript,node.js,Javascript,Node.js,这是作者表 const fieldSchema = { author_id: { type: Sequelize.INTEGER, primaryKey:true, autoIncrement:true }, name: { type: Sequelize.STRING, allowNull: false } const tableSchema = { tableName: 'author, order:'author_id' }; const Term
const fieldSchema = {
author_id: {
type: Sequelize.INTEGER,
primaryKey:true,
autoIncrement:true
},
name: {
type: Sequelize.STRING,
allowNull: false
}
const tableSchema = {
tableName: 'author,
order:'author_id'
};
const Term = db.define('author', fieldSchema, tableSchema);
这是图书模型。
const fieldSchema = {
book_id: {
type: Sequelize.INTEGER,
primaryKey:true,
autoIncrement:true
},
name: {
type: Sequelize.STRING,
allowNull: false
}
author_id: {
type: Sequelize.INTEGER,
allowNull: false
}
const tableSchema = {
tableName: 'author,
order:'author_id'
};
const Term = db.define('author', fieldSchema, tableSchema);
Book.belongsTo(Author, {foreignKey: 'author_id', targetKey: 'author_id', as: 'author', onDelete: 'cascade'});
当我删除一位作者时,与该作者相关的书不会被删除。
当我们写onDelete:“级联”应该可以工作,但它不工作
我做错什么了吗。请帮我解决这个问题,或者你可以建议我另一种方法
谢谢。检查数据库表中是否定义了“级联”规则。我以前也遇到过同样的问题,原因是它们没有在我的数据库中定义,我实际上必须在我的迁移中添加
onDelete
,等等。你是说在我的mysql数据库中。