diff --git a/stellarisdashboard/datamodel.py b/stellarisdashboard/datamodel.py index d049a9b..28ffa77 100644 --- a/stellarisdashboard/datamodel.py +++ b/stellarisdashboard/datamodel.py @@ -1462,7 +1462,7 @@ class Leader(Base): leader_id = Column(Integer, primary_key=True) game_id = Column(ForeignKey(Game.game_id)) - country_id = Column(ForeignKey(Country.country_id)) + country_id = Column(ForeignKey(Country.country_id), nullable=True) leader_id_in_game = Column(Integer, index=True) first_name = Column(String(80)) diff --git a/stellarisdashboard/parsing/timeline.py b/stellarisdashboard/parsing/timeline.py index fc9fc56..4b6e8c0 100644 --- a/stellarisdashboard/parsing/timeline.py +++ b/stellarisdashboard/parsing/timeline.py @@ -1334,8 +1334,15 @@ def _update_leader_attributes(self, country: datamodel.Country, leader: datamode leader.gender = leader_gender leader.species = leader_species leader.leader_traits = leader_traits - leader.country = country leader.ethic = ethic + + # apparently, setting leader.country = None deletes the entire leader from the DB + # but setting leader.country_id = None is fine + if country is None: + leader.country_id = None + else: + leader.country = country + self._session.add(leader) def _get_leader_traits(self, leader_dict) -> (str, str):