tortoise / aerich

A database migrations tool for TortoiseORM, ready to production.
https://github.com/tortoise/aerich
Apache License 2.0
843 stars 96 forks source link

aerich init raises KeyError: 'app' #61

Closed lucekdudek closed 4 years ago

lucekdudek commented 4 years ago

I cannot init aerich

aerich init -t app.database.tortoise.utils.TORTOISE_ORM gives me

...
File ".../bin/aerich", line 8, in <module>
    sys.exit(main())
  File ".../lib/python3.8/site-packages/aerich/cli.py", line 262, in main
    cli()
  File ".../lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File ".../lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File ".../lib/python3.8/site-packages/click/core.py", line 1256, in invoke
    Command.invoke(self, ctx)
  File ".../lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File ".../lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File ".../lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File ".../lib/python3.8/site-packages/aerich/cli.py", line 31, in wrapper
    Migrate.remove_old_model_file(ctx.obj["app"], ctx.obj["location"])
KeyError: 'app'

aerich init --app app ... and aerich --app app init ... gives me the same result even aerich init -h gives the same result

python 3.8.5(pipenv)/3.8.2(docker container) - same result aerich version: 0.3.0 tortoise version: 0.16.16 click version: 7.1.2

TORTOISE_ORM:

TORTOISE_ORM = {
    "connections": {"default": "postgres://postgres:postgres@database/emails"},
    "apps": {
        "models": {
            "models": ["app.database.tortoise.models", "aerich.models"],
            "default_connection": "default",
        }
    }
}

This works so I assume models and config are fine:

await Tortoise.init(config=TORTOISE_ORM)
await Tortoise.generate_schemas()

This is a bug or I am missing something but I couldn't find anything about it in web.

long2ice commented 4 years ago

You app is models rather than app, so you can ignore --app or --app models

lucekdudek commented 4 years ago

You app is models rather than app, so you can ignore --app or --app models

Ignoring --app or not gives the same result.

long2ice commented 4 years ago

I confirm that, which is a bug and I fixed it in https://github.com/tortoise/aerich/commit/1fde3cd04e68d56e4ee3f1a6e11078781fb63f91 ,update to lastest dev branch and try again.

long2ice commented 4 years ago

Fixed in release v0.3.1