Skip to content

Commit

Permalink
Fix drop model in the downgrade. (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
long2ice committed Mar 18, 2021
1 parent a19edd3 commit 505d361
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 58 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

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

### 0.5.0

Expand Down
6 changes: 5 additions & 1 deletion aerich/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ def diff_models(cls, old_models: Dict[str, dict], new_models: Dict[str, dict], u
model = cls._get_model(new_model_describe.get("name").split(".")[1])

if new_model_str not in old_models.keys():
cls._add_operator(cls.add_model(model), upgrade)
if upgrade:
cls._add_operator(cls.add_model(model), upgrade)
else:
# we can't find origin model when downgrade, so skip
pass
else:
old_model_describe = old_models.get(new_model_str)

Expand Down
114 changes: 57 additions & 57 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ class Config(Model):
value = fields.JSONField()
status: Status = fields.IntEnumField(Status)
user = fields.ForeignKeyField("models.User", description="User")


class NewModel(Model):
name = fields.CharField(max_length=50)
Loading

0 comments on commit 505d361

Please sign in to comment.