python
config_error
ai_generated
true
sqlalchemy.exc.NoForeignKeysError: Could not determine join condition between parent/child tables on relationship 'User.addresses' - there are no foreign keys linking these tables. Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression.
ID: python/sqlalchemy-missing-ondelete-option
80%Fix Rate
86%Confidence
0Evidence
2025-03-11First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
A relationship is defined without a foreign key constraint between the tables, or the FK is not properly declared.
generic中文
表之间定义关系时没有外键约束,或外键未正确声明。
Workarounds
-
95% success
class Address(Base): __tablename__ = 'addresses' user_id = Column(Integer, ForeignKey('users.id')) class User(Base): addresses = relationship('Address') -
80% success
class User(Base): addresses = relationship('Address', primaryjoin='User.id == Address.user_id')
Dead Ends
Common approaches that don't work:
-
60% fail
It's just a regular column; no constraint.
-
50% fail
May cause ambiguous joins.