Open syabro opened 3 years ago
If you use more than one app, use --app
option, or just use one
@long2ice emm, if I have 10 apps, I have to run command 10 times? It doesn't make any sense. Why not automatically split migrations by folders apps?
Usually one app one database
Why call it apps
then if you're emulating Django interface when app
has very different meaning?
yeah this bit me as well -- init-db
seems to create an initial migration for all apps, but then migrate
is only migrating the first app, here:
https://github.com/tortoise/aerich/blob/af632218750c1b6ee8571f70bd5de3d1eec3d2d2/aerich/cli.py#L76
I guess you're saying this is because init-db
keys on connection and migrate
keys on app name? The init-db piece seems to be happening here:
I guess I can work around this in my codebase by having two named DB connections? but this is bad in prod because it doubles the pool size. also when I tried it, I got a 'cyclic fk errors' error. it's also confusing that one command keys by connection, the other by app name.
possible solution: is it worth creating an --all-apps
flag for the migrate command? I'm happy to submit a PR if that's useful
I did a POC here with an --all-apps
flag https://github.com/abe-winter/aerich
It lets the init-db
and migrate
commands operate on multiple tortoise apps at once by supporting app=None
in a bunch of places
my use case for apps is to let a fastapi project import plugins which have sql tables that get included in migrations -- I may be misusing / misunderstanding what tortoise apps are for, sorry in advance if that's the case
another design approach: make --app
param support multiple entries, turn the app
state var into a list?
It would be nice to have per app functionality like Django, I have an application that needs to load apps modularly and having all of the migrations get merged into one file means I can't properly separate them.
Has there been any update on this, because I am having the same issue.
I made a slight hack to work around this, wrote a script to loop through the apps
keys of the config dict then ran the aerich command on each individually.
errors = []
for app in apps:
if os.system(f"aerich --app {app} {command}"):
errors.append(app)
if errors:
print("Errors encountered on %" % ",".join(errors))
If not --app
specific, maybe we should migrate all app default
If not
--app
specific, maybe we should migrate all app default
That would be the expected behavior.
PR is welcome!
I have config
When I run
init-db
I gotZendr app models were put into thirdparty directory. I expect it to have
thirdparty
andzendr
folders.What do I do wrong?