2

According to the alembic documentation, if I want to get the migrations history, I just need to do:

from alembic import command
from alembic.config import Config

alembic_cfg = Config("./alembic.ini")
command.history(alembic_cfg)

And I should be able to see the history, but it's actually returning null, even though when I run in the terminal: alembic history, displays correctly. I also tried to do os.system('alembic history'), but also returns null. Any idea how to fix this?

1 Answers1

0

Not exactly straightforward, but console output can be captured via the stdout argument:

from io import StringIO

from alembic import command
from alembic.config import Config

output = StringIO()

alembic_cfg = Config("./alembic.ini", stdout=output)
command.history(alembic_cfg)

output.seek(0)
print(output.read())
Arnaud P
  • 12,022
  • 7
  • 56
  • 67