klen / peewee_migrate

Simple migration engine for Peewee

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug report: Self foreign keys are not handled

norbertcyran opened this issue · comments

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")
  1. Create a migration
  2. Run the migration

Expected behavior
Migration should pass correctly.

Desktop (please complete the following information):

  • Version 1.4.2