SQLAlchemy + pgadmin4 Allowing Dupes on Unique Column

29 Views Asked by At

Seeing some weird behavior that I can't explain while using pgadmin4 and SQLAlchemy. I have a user model with a unique constraint on email. However, when creating users in pga4, I'm able to create one duplicate email before pga4 throws a unique constraint error.

In this screenshot, I have already successfully created a user with a duplicate email address as the first user. Then I try to create a third user with the same email address and it is throwing that constraint.

Here is my model code, it's pretty straightforward:

class User(Base):
    ''' Define user model '''
    __tablename__ = 'users'

    id = Column(Integer, primary_key=True, nullable=False)
    email = Column(String, nullable=False, unique=True)
    password = Column(String, nullable=False)
    created_at = Column(TIMESTAMP(timezone=True),
                        nullable=False, server_default=text('now()'))

I've dropped the table a couple of times and re-created it. I created one user, saved it. Then successfully created the duplicate user and saved again. So it's not a matter of saving the first two users at the same time.

0

There are 0 best solutions below