Correction clés étrangères
This commit is contained in:
@ -123,7 +123,7 @@ class ResultatsDepartement(Base):
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
dpt_id: Mapped[str] = mapped_column(ForeignKey("departement.code_insee"))
|
||||
resultats_region_id: Mapped[int] = mapped_column(ForeignKey("resultats2024_region.id"))
|
||||
resultats_region_id: Mapped[int] = mapped_column(ForeignKey("resultats2024_region.id"), nullable=True)
|
||||
inscrits: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
votants: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
abstentions: Mapped[int] = mapped_column(Integer(), default=0)
|
||||
|
@ -149,8 +149,12 @@ def importer_resultats_departements(engine: Engine, debug: bool = False) -> None
|
||||
resultats_departement.nuls = resultats["nuls"]
|
||||
resultats_departement.exprimes = resultats["exprimes"]
|
||||
else:
|
||||
resultats_region = session.execute(select(ResultatsRegion).filter_by(region_id=reg_code)) \
|
||||
.scalar_one_or_none()
|
||||
|
||||
resultats_departement = ResultatsDepartement(
|
||||
dpt_id=dpt_code,
|
||||
resultats_region_id=resultats_region.id if resultats_region else None,
|
||||
inscrits=resultats["inscrits"],
|
||||
abstentions=resultats["abstentions"],
|
||||
votants=resultats["votants"],
|
||||
|
Reference in New Issue
Block a user