Skip to content

Commit 505d361

Browse files
committed
Fix drop model in the downgrade. (#132)
1 parent a19edd3 commit 505d361

File tree

5 files changed

+71
-58
lines changed

5 files changed

+71
-58
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Fix tortoise connections not being closed properly. (#120)
88
- Fix bug for field change. (#119)
9+
- Fix drop model in the downgrade. (#132)
910

1011
### 0.5.0
1112

aerich/migrate.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ def diff_models(cls, old_models: Dict[str, dict], new_models: Dict[str, dict], u
169169
model = cls._get_model(new_model_describe.get("name").split(".")[1])
170170

171171
if new_model_str not in old_models.keys():
172-
cls._add_operator(cls.add_model(model), upgrade)
172+
if upgrade:
173+
cls._add_operator(cls.add_model(model), upgrade)
174+
else:
175+
# we can't find origin model when downgrade, so skip
176+
pass
173177
else:
174178
old_model_describe = old_models.get(new_model_str)
175179

poetry.lock

+57-57
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/models.py

+4
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,7 @@ class Config(Model):
6666
value = fields.JSONField()
6767
status: Status = fields.IntEnumField(Status)
6868
user = fields.ForeignKeyField("models.User", description="User")
69+
70+
71+
class NewModel(Model):
72+
name = fields.CharField(max_length=50)

0 commit comments

Comments
 (0)