I have this data model in ORM.
class Region(db.Model):
__tablename__ = 'region_master'
region_master_id = db.Column(
db.Integer,
primary_key=True,
autoincrement=True
)
region_name = db.Column(db.Text)
Now suppose if I insert data in region_master by orm
db.Region(region_name="APAC") --> database allocates region_master_id = 1 by using region_master_region_master_id_seq (this is created by default by postgres as I am using autoincrement=True)
but now suppose I insert data using sql query then it skips the sequence(region_master_region_master_id_seq) and inserts data by given id.
INSERT INTO public.region_master (region_master_id, region_name) VALUES (2, N'Europe');
INSERT INTO public.region_master (region_master_id, region_name) VALUES (3, N'USA');
Now sequence returns 1 as last_value:
select last_value from region_master_seq
Now again if I insert using ORM I get unique key constraints error.
dm.Region(region_name="EMEA")
Here DB tries to allocate region_master_id=2 and it fails with unique key constraints.
So is there any way that ORM/database will take 4 as next id.