Tuesday 16 May 2017

Add new entry to database with primary key automatically updated postgresql and nodejs

I am building something where I need to add a new entry into an existing table but error says
duplicate key value violates unique constraint "tblDistricts_pkey" detail: 'Key ("districtId")=(11) already exists.',

maybe because all the previous entries have been inserted using pgAdmin and these are being added from the front end. My table has 22 entries. I was thinking maybe I can get the number of rows in my table and then +1 the primary key everytime new entry is done. But I dont know how to get number of rows in backend.

Or if there is any other better way, then do let me know.



via Uday Saini

No comments:

Post a Comment