klen / peewee_migrate

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

Migration failed, keyerror, migrator.orm is empty #163

Open simse opened 4 years ago

simse commented 4 years ago

I'm trying to add a field using the following code: migrator.add_fields('Script', 'cron')

This is the ouput: Migration failed: 001_add_cron Traceback (most recent call last): File "/mnt/c/Users/Simon Sorensen/Documents/GitHub/chronos/.venv/lib/python3.6/site-packages/peewee_migrate/router.py", line 153, in run_one migrate(migrator, self.database, fake=fake) File "<string>", line 39, in migrate File "/mnt/c/Users/Simon Sorensen/Documents/GitHub/chronos/.venv/lib/python3.6/site-packages/peewee_migrate/migrator.py", line 105, in wrapper return method(migrator, migrator.orm[model], *args, **kwargs) KeyError: 'Script' Traceback (most recent call last): File "chronos.py", line 9, in <module> from chronos.runtime import * File "/mnt/c/Users/Simon Sorensen/Documents/GitHub/chronos/chronos/runtime.py", line 10, in <module> import chronos.metadata File "/mnt/c/Users/Simon Sorensen/Documents/GitHub/chronos/chronos/metadata.py", line 57, in <module> router.run() File "/mnt/c/Users/Simon Sorensen/Documents/GitHub/chronos/.venv/lib/python3.6/site-packages/peewee_migrate/router.py", line 182, in run self.run_one(mname, migrator, fake=fake, force=fake) File "/mnt/c/Users/Simon Sorensen/Documents/GitHub/chronos/.venv/lib/python3.6/site-packages/peewee_migrate/router.py", line 153, in run_one migrate(migrator, self.database, fake=fake) File "<string>", line 39, in migrate File "/mnt/c/Users/Simon Sorensen/Documents/GitHub/chronos/.venv/lib/python3.6/site-packages/peewee_migrate/migrator.py", line 105, in wrapper return method(migrator, migrator.orm[model], *args, **kwargs) KeyError: 'Script'

It looks like migrator.orm is empty. What am I doing wrong?

simse commented 4 years ago

Prettier output: https://pastebin.com/Dtnfey8S

revolter commented 4 years ago

Same issue

dmiwell commented 4 years ago

Looks like the issue happens because of some imports. I know that there is an issue with relative imports, so it fails while compiling migration file code with something like KeyError: "'__name__' not in globals".

Script key is not something from the pacakge code, so I assume the issue is some combination of imports and compilation of migration code.

@simse make sure your code is fine. I'm not sure if import * could be executed fine.

Probably the related thing to start from is peewee_migrate.router.Router.read

dmiwell commented 4 years ago

@revolter this package seems to not being supported now, so if you are interested in it check https://github.com/spumer/peewee_migrate2