我的项目中有一个Department
模型。属性为id
、name
。name
当然应该是唯一的。然而,我似乎看不到设置在哪里,所以我可以放一些类似的东西
@model()
export class Department extends Entity {
@property({
type: 'number',
id: true,
generated: true,
})
id?: number;
@property({
type: 'string',
required: true,
unique: true // ---> This is what I want. But how?
})
name: string;
constructor(data?: Partial<Department>) {
super(data);
}
}
我试着挖掘Model文档,似乎可以用@model
装饰器做一些事情。然而,我没有发现任何关于它的文件。
此外,我想在PostgreSQL中作为数据源来做这件事。有线索吗?如有任何建议,我们将不胜感激。
@属性({类型:'string',required:true,索引:{独特:真实,}}(name:字符串;
正在使用索引对象。
迁移数据库-修改或更改表
run命令:npm run build迁移数据库:npm run migrate