Skip to content
Advertisement

ID primary key of ONE to MANY related tables jumping numbers with POSTGRESQL

I am having an issue where the id column of tables users and posts are jumping in increments

users and have many notes ==> one to many relationship

table users

table notes

what is happening is the id column of the two tables jump…if there is 3 in id of notes, then next if for users will be 4

how can i fix this issue? or is this normal?

here is the alembic file used to create the schema

and here is what i have in my models.py file for python to interact with the database

so what did i do wrong and how do i fix the issue?

UPDATE

here is an example query to insert rows into users table

here is an example query to insert rows into notes table

could this the issue?

change nextval('users_id_seq') to nextval('notes_id_seq')?

Advertisement

Answer

Fix was to fix the INSERT query that populates the notes table

FROM

TO

this solved my problem

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement