0

I have ported a database from MySQL to Postgresql, running behind a django app on heroku.

In adding new rows to tables, Postgres is going back to the start of the id's, in effect starting at 1. I'd deleted some data, say the id's 1, 2 and 3. Now I'm trying to add a new row, which should be id=137, it's trying to use id=4, which already exists. How do I get Postgres to 'refresh' it's auto-id for new rows and find the next available id? Is there some way to do this in Django or in pgAdmin?

1 Answer 1

2

You should use function setval():

SELECT setval('mytable_mycolumn_seq', 136); -- Next nextval will return 137

Read more.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.