class Prediction(Base, UUIDMixin): __tablename__ = "predictions"
location_id: Mapped[UUID] = mapped_column(ForeignKey("locations.id")) location: Mapped[Location] = relationship( back_populates="predictions", foreign_keys=[location_id] ) underlying_predictions: Mapped[list["Prediction"]] = relationship( "Prediction", secondary=prediction_relations, primaryjoin="Prediction.id == prediction_relations.c.dependant_prediction_id", secondaryjoin="Prediction.id == prediction_relations.c.underlying_prediction_id", back_populates="dependant_predictions", ) dependant_predictions: Mapped[list["Prediction"]] = relationship( "Prediction", secondary=prediction_relations, primaryjoin="Prediction.id == prediction_relations.c.underlying_prediction_id", secondaryjoin="Prediction.id == prediction_relations.c.dependant_prediction_id", back_populates="underlying_predictions", ) [/code] Когда я пытаюсь добавить прогноз, в основе которого лежит прогноз, я получаю следующую ошибку: [code]sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) NOT NULL constraint failed: predictions.location_id[/code]. Можно ли хранить их оба вместе или мне нужно сначала зафиксировать базовый прогноз, прежде чем можно будет зафиксировать зависимый прогноз?