tortoise / aerich

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

NonExistentKey when running `aerich init` #284

Open homm opened 1 year ago

homm commented 1 year ago
# aerich init -t project.settings.DATABASE 
...
  File "/usr/local/lib/python3.11/site-packages/aerich/cli.py", line 205, in init
    doc["tool"]["aerich"] = table
    ~~~^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/tomlkit/container.py", line 650, in __getitem__
    raise NonExistentKey(key)
tomlkit.exceptions.NonExistentKey: 'Key "tool" does not exist.'

My pyproject.toml:

[project]
name = "project"
classifiers = ["Private :: Do Not Upload"]
version = "0"
dependencies = [
    "fastapi ~= 0.89.1",

    # DB
    "tortoise-orm[accel,asyncpg] ~= 0.19.2",
    "aerich ~= 0.7.1",
]

[project.optional-dependencies]
dev = [
    "pytest ~= 7.2.1",
    "isort ~= 5.11.4",
    "flake8 ~= 5.0.4",
    "ipython",
]
woopla commented 9 months ago

I've just had the same issue. This is because aerich init assumes the [tool] section exists in pyproject.toml. You can work around that by creating the section yourself, but aerich should check if it exists first...

saifullah-repliq commented 2 weeks ago

I also have faced this issue. Is there any solution?

shahriar350 commented 2 weeks ago

Solution is:

Create a file in your root project pyproject.toml

Here is my toml file. Please customize this as you needed

[project]
name = "project_name"
classifiers = ["Private :: Do Not Upload"]
version = "1"
dependencies = [
    "blacksheep==2.0.7",

    # DB
    "tortoise-orm[asyncpg] ~= 0.21.3",
    "aerich ~= 0.7.2",
]

[project.optional-dependencies]
dev = [
]
[tool.setuptools.packages] // this is important. If you don't add this link, you will get an error
find = {}  # Scanning implicit namespaces is active by default