I am facing a weird problem using alembic migration. I am using Postgres as DB.
I have written an alembic revision where I am inserting some data in a table(There is already some data in the table before migration).
The issue is the migration runs successfully and inserted the data in the table. But after this when I am calling an api and trying to insert a new row I get some error, because table seq_id is not incremented.
ERROR:__name__:Failed to create a duplicate entry: (psycopg2.IntegrityError) duplicate key value violates unique constraint "user_pkey"
DETAIL: Key (id)=(9) already exists.
[SQL: 'INSERT INTO user (id, name, age, number) VALUES (%(id)s, %(name)s, %(age)s, %(number)s) RETURNING id'] [parameters: {'number': None, 'id': 9, 'name': 'something', 'age': 12}]
Let's take an example:
I have table "User" which already have 10 rows, now using alembic migration I am inserting two rows so now there are 12 rows. Ideally, it should update the sequence_id too, but seq_id is still at 10.
No using an api I am inserting on more row which it will try to add at id 11 and will give the above error. If I try this api two more times then it will be a success because it will increment the seq_id every time.
This is happening only after applying alembic migration, else it is working fine.
Can anyone tell me what I am doing wrong, did I miss any config, why the sequence id is not incrementing while applying migration?
Thanks in advance!