klen / peewee_migrate

Simple migration engine for Peewee
MIT License
353 stars 86 forks source link

Bug report: Self foreign keys are not handled #202

Closed norbertcyran closed 3 years ago

norbertcyran commented 3 years ago

Describe the bug After creating the migration with the model containing foreign key to itself, migration is failing due to KeyError. After quick investigation, the exact line containing the bug is ForeignKeyField(model=migrator.orm["model"], ...). During execution of this code, "model" is not yet added to migrator.orm dict. Instead, the call should look like: ForeignKeyField(model="self", ...). After changing it the proposed way, migration has completed successfully.

To Reproduce Steps to reproduce the behavior:

  1. Write a model containing a self-referencing foreign key:
    class TestModel(Model):
    parent = ForeignKeyField("self")
  2. Create a migration
  3. Run the migration

Expected behavior Migration should pass correctly.

Desktop (please complete the following information):