Pg: Inserting new data with auto increment column
I am getting error while inserting data to postgres from nextjs api. Error: detail: 'Key (id)=(21) already exists.',
I have table with three columns and the API is submitting values as name and status. I am guessing postgres would take care of auto increment. what is the issue here ?
API
3 Replies
Full error msg:
If the data you're passing to insert has an
id
field, it will be sent to the database
That's why you're getting the errorNo, I did not include ID field in json data. This was another weird issue from poatgres Aurora. I have table with 25 records, manually uploaded using csv file. For some reason, database was considering 21 as latest available auto id. I tried 4 times to push the data from API and it failed. It finally reached 26 and API call was success. It is working fine now. I have no idea what caused auto increment to fail from db side.