1

I want to use alembic.py for configuration instead of alembic.ini.
But I can't find any example of that type of configuration.
Is there any way to not use alembic.ini?

Jony cruse
  • 815
  • 1
  • 13
  • 23

1 Answers1

4

Are you looking for this:

from alembic.config import Config
alembic_cfg = Config()
alembic_cfg.set_main_option("script_location", "myapp:migrations")
alembic_cfg.set_main_option("url", "postgresql://foo/bar")
alembic_cfg.set_section_option("mysection", "foo", "bar")
Sait
  • 19,045
  • 18
  • 72
  • 99
  • This is exactly what I wanted. How can I specify this custom config `.py` file when execute alembic command? – Jony cruse Jul 06 '15 at 06:29
  • Save this file as `alembic_config_file.py` and import it from your application in the beginning. – Sait Jul 06 '15 at 07:11
  • 1
    Also please consider [upvoting](http://meta.stackexchange.com/questions/173399/how-to-upvote-on-stack-overflow) or marking it answer by clicking the tick if it helped you. – Sait Jul 06 '15 at 07:12
  • The new document Url can be found at https://alembic.sqlalchemy.org/en/latest/api/config.html – sparrow Mar 06 '19 at 09:15