aerich
aerich copied to clipboard
NonExistentKey when running `aerich init`
# 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",
]
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...
I also have faced this issue. Is there any solution?
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