Loopback-next: How to create postgresql serial type primary key when auto-migrate

Created on 18 Mar 2019  路  2Comments  路  Source: strongloop/loopback-next

This is my user model,

@model()
export class User extends Entity {
@property({
type: 'number',
id: true,
})
id?: number;

@property({
type: 'string',
required: true,
})
user_name: string;
@property({
type: 'string',
required: false,
})
role: string;

@property({
type: 'string',
required: true,
})
password: string;

When i'm run "npm run migrate -- --rebuild" it creates primary key data type as "integer" in postgresql. Then primary key is not auto increment. Because "npm run migrate " create user table primary key data type as "integer". I want to make it as "SERIAL" type.
Could you please tel me how do i resolve this problem.

Most helpful comment

Add the generated property.

@property({ id: true, index: true, generated: true, })

Try using the search function in future. It might be found quickly.

All 2 comments

Add the generated property.

@property({ id: true, index: true, generated: true, })

Try using the search function in future. It might be found quickly.

It works....!!! Thanks for your quick response.

Was this page helpful?
0 / 5 - 0 ratings