I am trying to create an partial unique index only for the column whose value is null, this is my db model in SQL alchemy, and this is how I tried to create the partial index.
class RequestedTarget(db.Model):
__tablename__ = "example"
id = Column(UUIDType(), primary_key=True, default=uuid4)
table1_id= Column(String(), ForeignKey("table1.id"), nullable=False)
table2_id= Column(String(), ForeignKey("table2.id"))
__table_args__ = (
Index("single_root_target", table1_id, table2_id, unique=True, postgresql_where=table2_id.is_(None)),)
But when I run my program, I am still able to create two records with table1_id = x and table2_id = null. please let me know when I have gone wrong.