peewee_migrate
peewee_migrate copied to clipboard
`ForeignKeyField` nonsupport 'self'
models.py
class Group(BaseModel):
name = pw.CharField(max_length=255, null=False, unique=True)
parent = pw.ForeignKeyField('self', null=True, related_name='children')
description = pw.CharField(max_length=255, null=True)
def __str__(self):
return self.name
migrations/001_auth.py
def migrate(migrator, database, fake=False, **kwargs):
@migrator.create_model
class Group(pw.Model):
name = pw.CharField(max_length=255, unique=True)
parent = pw.ForeignKeyField(db_column='parent_id', rel_model=migrator.orm['group'], related_name='children', to_field='id')
description = pw.CharField(max_length=255, null=True)
class Meta:
db_table = "group"
errors
➜ ams-api git:(master) ✗ python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 71, in <module>
cli()
File "/Users/tux/.pyenv/versions/3.6.1/envs/sanic-ams-api/lib/python3.6/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/Users/tux/.pyenv/versions/3.6.1/envs/sanic-ams-api/lib/python3.6/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/Users/tux/.pyenv/versions/3.6.1/envs/sanic-ams-api/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/tux/.pyenv/versions/3.6.1/envs/sanic-ams-api/lib/python3.6/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/tux/.pyenv/versions/3.6.1/envs/sanic-ams-api/lib/python3.6/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "manage.py", line 32, in migrate
migrations = router.run(name, fake=False)
File "/Users/tux/.pyenv/versions/3.6.1/envs/sanic-ams-api/lib/python3.6/site-packages/peewee_migrate/router.py", line 170, in run
self.run_one(mname, migrator, fake=fake, force=fake)
File "/Users/tux/.pyenv/versions/3.6.1/envs/sanic-ams-api/lib/python3.6/site-packages/peewee_migrate/router.py", line 140, in run_one
migrate(migrator, self.database, fake=fake)
File "<string>", line 94, in migrate
File "<string>", line 96, in Group
KeyError: 'group'