【发布时间】:2021-08-24 04:04:03
【问题描述】:
如何允许外键为空?我有一个through 和belongsToMany 关联:
Shelf
belongsToMany(Book, { through: Library, as: "Books"});
Book
belongsToMany(Shelf, { through: Library, as: "Shelves"});
Library
section: DataTypes.STRING,
// ... other fields
我想在bookId 上录制null Library:
Library.create({
section: "blah",
bookId: null,
shelfId: 3
});
由于 Sequelize 自动在连接表 Library 中创建 bookId 和 shelfId,我将如何指定我希望在 bookId 的外键上允许 null Library?
【问题讨论】:
标签: javascript node.js postgresql sequelize.js