tortoise / aerich

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

ValueError: Empty module name #26

Open maxim-s-barabash opened 4 years ago

maxim-s-barabash commented 4 years ago

aerich 0.2.1 tortoise-orm 0.16.12

I accidentally specified the wrong module name and got an error

aerich init --location . -t help
Success create migrate location .
Success generate config file aerich.ini

aerich.ini

[aerich]
tortoise_orm = help
location = ./
aerich init-db
...
File "/usr/local/lib/python3.7/dist-packages/aerich/cli.py", line 58, in cli
    tortoise_config = get_tortoise_config(ctx, tortoise_orm)
File "/usr/local/lib/python3.7/dist-packages/aerich/utils.py", line 38, in get_tortoise_config
    config_module = importlib.import_module(config_path)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1003, in _gcd_import
File "<frozen importlib._bootstrap>", line 942, in _sanity_check
ValueError: Empty module name
long2ice commented 4 years ago

Just run aerich init

trevordanahy commented 3 years ago

I am having the same problem, but I think my problem is my own misunderstanding of what is needed in config. I have a fastapi app, with the file structure below. What am I doing wrong? Thank you

app
    |-- main.py
    |-- db
           |-- models.py
           |-- schemas.py
    |-- auth
           |-- users.py 

Here is my config setup,(from main.py) I'm specifically unsure what is being represented under the apps key.

 tortoise_config = {
    "connections": {"default": "postgres://user:password@localhost:5432/mydb"},
    "apps": {
        #should this key be fastapi appname or my project folder
        "app": {
            #i've seen this key as modules or models, im not sure which is correct
            "models": ["db.models", "aerich.models"],
            "default_connection": "default",
        },
    },
}

register_tortoise(
    app,
    config=tortoise_config,
    generate_schemas=True,
    add_exception_handlers=True
)
long2ice commented 3 years ago

Just manual update content in aerich.ini or delete it and rerun aerich init -t tortoise_config_path