Is it possible to have models with same name but on different files when autogenerating migrations? #988
Unanswered
oaltun
asked this question in
Usage Questions
Replies: 1 comment
-
Hi, I think the issue here is different. Alembic has no knowledge of the models, it only deals with tables. In the example you have, is the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
E.g.
In
app.support.models.py
And in
app.blog.models.py
Notice that the table names are different, so there should be no problem on the database side.
I think this can be needed for large applications, also for apps that want to support things like plugins/apps/namespaces/blueprints. But I was not able to make it work.
At first I tried to approach like adding following in
alembic/env.py
:But I get an error about "duplicate keys" when autogenerating migrations. Applying existing migrations works fine, but I can not autogenerate. The documentation says keys are a combination of schema and tablenames. I dont know what a schema is, but tablenames are different here.
At this point to use separate *.model.py files I am importing all *.models.py files into a main models.py and use that in env.py.
E.g. in
app.models.py
:and in
alembic/env.py
:This works for using different models.py files for each section of my application, but it squashes any chances of using any model names in more than one files.
Beta Was this translation helpful? Give feedback.
All reactions