4

I have two fields:

class Person(base):
     field1 = Column(String(32), unique=True, nullable=True)
     field2 = Column(String(128), unique=True, nullable=True)
     field3 = ...
     ...

I need to create a constraint, to check if at least one of [field1, field2] is available. I guess I need to use CheckConstraint, but I failed to get a result. Any ideas?

Farshid Ashouri
  • 16,143
  • 7
  • 52
  • 66

1 Answers1

7

Thanks to this post:

__table_args__ = (
        CheckConstraint('NOT(field1 IS NULL AND field2 IS NULL)'),
        )
Community
  • 1
  • 1
Farshid Ashouri
  • 16,143
  • 7
  • 52
  • 66