I have a model class :
class User(PBase):
__tablename__ = "users"
id = Column(Integer, primary_key=True)
name = Column(String, nullable=False, unique=True)
Now as per the documentation , when type Integer is used along with primary_key , a sequence is generated automatically. Here is the output table
id | integer | not null default nextval('users_id_seq'::regclass)
As you can see a default sequence is generated in the modifiers column.
But when I try to add the second user, I get integrity error on primary key constraint.
IntegrityError) duplicate key value violates unique constraint "users_pkey"
DETAIL: Key (id)=(1) already exists.
What is wrong here?
Edit: Code for adding the user, a snap shot
def create(name, email, roleid)
with self._session_context() as session:
user = User(name, email, roleid)
session.add(user)
session.commit()