diff --git a/ic_python_db/entity.py b/ic_python_db/entity.py index 9633970..893897d 100644 --- a/ic_python_db/entity.py +++ b/ic_python_db/entity.py @@ -180,7 +180,8 @@ class User(Entity): setattr(self, k, v) self._do_not_save = False - self._save() + if not self._loaded: + self._save() @classmethod def new(cls, **kwargs): @@ -386,6 +387,10 @@ def load( # Create instance first entity = cls(**data, _loaded=True) + # If migration was applied, persist the migrated data + if stored_version != current_version: + entity._save() + # Restore legacy "relations" block if present in serialized data. # Otherwise keep the _relations that __init__ already populated # via relationship descriptors (OneToMany, ManyToOne, etc.).