Since sqlalchemy.orm.relationship()
already implies the relation, and I do not want to create a constraint in db. What should I do?
Currently I manually remove these constraints after alembic migrations.
Since sqlalchemy.orm.relationship()
already implies the relation, and I do not want to create a constraint in db. What should I do?
Currently I manually remove these constraints after alembic migrations.
Instead of defining "schema" level
ForeignKey
constraints create a custom foreign condition; pass what columns you'd like to use as "foreign keys" and theprimaryjoin
torelationship
. You have to manually define theprimaryjoin
because:Foreign keys can also be annotated inline in the
primaryjoin
usingforeign()
:You can verify that no
FOREIGN KEY
constraints are emitted for table c:Warning:
Note that without a
FOREIGN KEY
constraint in place on the DB side you can blow your referential integrity to pieces any which way you want. There's a relationship at the ORM/application level, but it cannot be enforced in the DB.