1
我想通過使用Sequelize和Postgresql顯式創建的聯結表添加多對多關係。Sequelize重複鍵約束違規
的關係兩側的表是這樣的關聯:
Shop.belongsToMany(models.user, {through: 'visits' })
User.belongsToMany(models.shop, {through: 'visits' })
而且探訪結表的主鍵的定義是這樣的:
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true // Automatically gets converted to SERIAL for postgres
}
當我嘗試插入訪問我得到以下錯誤:
ERROR: duplicate key value violates unique constraint "visits_shopId_userId_key"
DETAIL: Key ("shopId", "userId")=(1, 12) already exists.
做了一個pg_dump後,我有tr通過向模型添加約束:false來刪除組合鍵約束,但我仍然收到錯誤。
(I已經下降的表和重新同步在調試過程中幾次)