-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to let app insert id automatically? #811
Comments
@ri8ika, IIRC, last time I got it to work for postgresql is:
In case you're running issue with the postgresql setup, I've put together some information here: https://medium.com/loopback/loopback-4-todo-list-example-switching-to-a-sql-or-nosql-database-24cd68cf3647. |
Ah, I tried it but still getting error:
|
@ri8ika , I just tried it out.
Please note that the |
Sorry, still not working for me. Maybe the type is string in my case?
|
I just tried using number, but still getting same error. Are you also using postgres? |
Yes, I'm using postgres. I assume you're not using the
See the I'm hitting a bug described in here: loopbackio/loopback-next#2398. |
@ri8ika, I think I might know the key to get this to work. I created the table on postgresql using I've tried it with column type being Assuming you created the table outside of LoopBack, did you set up the auto-increment for that column? I'm reading this.. http://www.postgresqltutorial.com/postgresql-serial/ |
Hmm, I had run the migration, but currently not seeing such |
did you run |
Never. But why to run build? I'm testing it in development. Still no luck running after build. |
I will try to figure out on this later. But I'm facing a major issue. Can you please help me on this? https://github.com/strongloop/loopback.io/issues/813 The repo I have hosted in heroku is: github.com/bhojport/nexserver |
@ri8ika , i just had a chance to review your repo, and noticed that the id field is optional. https://github.com/bhojport/nexserver/blob/master/src/models/product.model.ts#L43-L48. It should be the following instead:
You can see my example here. |
@dhmlau Yes, it's optional there. I have not updated the repo. But as per your suggestion, I already tried and didn't get it working - locally and so not updated in repo. |
@ri8ika , I haven't got a chance to run your example. But if it's the same as my example, try running |
Sorry, I can't migrate the db in heroku so stopped working on it. |
loopback has the worst docs |
Just ran into a similar issue. As @dhmlau pointed out, the |
@ctrevisan thank you!!! |
This remove table data, this is not good solution if you do not want to loss data |
@ctrevisan If you are using Postgres db then you can use query to set default value to primary |
In loopback 3, the id was inserted automatically. But in loopback 4, it is required even when creating models.
After removing the required: true option worked when I was working with mongodb - the id was created automatically when post request happens. But for giving it a try to live on heroku, I needed to use postgres rather than mongodb. So, I decided to create new project locally and using postgresql the preceeding way didn't work.
Meaning removing
required: true
doesn't work. Even havingrequired: false
doesn't work.Is there any way to have id not required when inserting data so that it can insert automatically?
PS: If I remove the id property the app will not work:
Property 'id' does not exist
. I hope there should be a way.The text was updated successfully, but these errors were encountered: