loopback-next icon indicating copy to clipboard operation
loopback-next copied to clipboard

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

Open DilupaSampath opened this issue 7 years ago • 2 comments

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.

DilupaSampath avatar Mar 18 '19 07:03 DilupaSampath

Add the generated property.

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

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

dougal83 avatar Mar 18 '19 09:03 dougal83

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

DilupaSampath avatar Mar 18 '19 11:03 DilupaSampath