Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
Where should I put alembic's generated folder?

I'm starting a fastapi project, and using sqlalchemy + alembic to manage the sqlite db. Everything worked fine till alembic.

Here's the project folder structure:

app/
  - api/
  - core/
    - __init__.py
    - settings.py
  - db/
    - __init__.py
    - database.py

(I put a __init__.py in all folders)

At first, I tried to create migration folder inside db/, but with no success (same error as below). So I did alembic init migrations in root folder app/.

Now the folder looks like:

app/
  - api/
  - core/
    - __init__.py
    - settings.py
  - db/
    - __init__.py
    - database.py
  - migrations/
    - versions/
    - env.py
  - alembic.ini

And I modified the env.py:

from ..db.database import Base
from ..core.settings import settings

target_metadata = Base.metadata

def get_url():
    return settings.db_url

Then in app/, I tried

  • alembic revision --autogenerate -m "init"
  • python -m alembic.config revision --autogenerate -m "init"

But all complained:

...
  from ..db.database import Base
ImportError: attempted relative import with no known parent package

And since we have prepend_sys_path = . in alembic.ini, so imports like from db.database import Base would work. However I used relative imports in db/database.py and core/settings.py and all other files too and don't want to modify the codes.

My questions are:

  • Maybe I could put the migration folder outside the app/ and change relative import to app.db.database?
  • this might work for a single top level app, but what if I have several sub applications (app/subapps/sub1, app/subapps/sub2), and want to manage separated sqlite file for each sub application?
  • or maybe alembic is just not the right choice for my use case?
over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda