带有sequize -typescript和node-sqlite3的复合主键



如何使用sequelize-typescript创建以下复合主键(使用sqlite) ?

CREATE TABLE files(
`hash` VARCHAR(255) NOT NULL UNIQUE,
`filePath` VARCHAR(255) NOT NULL UNIQUE,
PRIMARY KEY(hash, filePath)
);

第二次插入hash失败:

@Table({
tableName: 'files'
})
class File extends Model {

@PrimaryKey
@Column({
unique: true,
allowNull: false,
})
hash!: string

@PrimaryKey
@Column({
unique: true,
allowNull: false,
})
filePath!: string
}

我刚刚发现我必须删除两个unique: true,声明。现在,sql和行为符合预期。

最新更新