Questions tagged [alembic]

Alembic is a lightweight database migration tool for usage with the SQLAlchemy Database Toolkit for Python.

Alembic is a lightweight database migration tool for usage with the SQLAlchemy Database Toolkit for Python.

Some of the important operations that can be performed with alembic are

  • Upgrade(Perform Database migrations, Example: create/alter/modify)
  • Downgrade(Its the reverse operation of upgrade to undo the upgrade changes)
  • Current(Show the current revision and state of migration in the database)
  • Init(Initialize a new scripts directory)
  • Revision(Create a new revision file)

Related tags

References

854 questions
3
votes
3 answers

How to autogenerate and apply migrations with alembic when the database runs in a container?

I find the workflow for working with database migrations in a containerized environment confusing. I have a web API with an attached database. The API runs in one container and the database in another. The project file structure is as follows . ├──…
Hunter2
  • 35
  • 1
  • 1
  • 6
3
votes
0 answers

Alembic not loading config member

We're working on a project which uses Postgresql as a data source which is then managed/initiated using SqlAlchemy to create models, and Alembic for migrations. The issue is that Alembic cannot auto-generate any new migrations, nor can it upgrade…
3
votes
1 answer

How to add a column after another column in sqlalchemy for mysql?

I have a table where I need to add column say a_1 after column a and the table structure is like column a,b,c,d? How can i add this? Below query adds column after d but I want to add column after a? def upgrade(): # ### commands auto generated by…
3
votes
0 answers

Alembic env.py doesn't read environment variables in Flask project

I'm using Alembic in a Flask project in PyCharm IDE and I would like to use environment variables instead of storing database configurations in the alembic.ini file. So this is my modified env.py import os ... def get_url(): return…
dust
  • 31
  • 3
3
votes
0 answers

Add a second db to alembic context

I'd like to connect to a second external database during my migration to move some of its data into my local database. What's the best way to do this? Once the second db has been added to the alembic context (which I am not sure of how to do), how…
jgozal
  • 1,480
  • 6
  • 22
  • 43
3
votes
1 answer

Getting 'could not translate host name "db" to address' when trying to create database migration

I'm using FastAPI and postgresql to build a simple python api backend. When I try to build the database migration file (using Alembic) this error occures: sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name…
Saeed Esmaili
  • 764
  • 3
  • 12
  • 34
3
votes
1 answer

flask-migrate/alembic fails with `ValueError: not enough values to unpack (expected 2, got 1)` when running db migrate

I have created a Flask app which currently has around ~30 models. So far, when I was testing everything locally, I had a local Postgresql docker container on which I would use SQLAlchemy().create_all() to create all tables. That worked great so far.…
Moshe Vayner
  • 738
  • 1
  • 8
  • 23
3
votes
0 answers

How do I configure alembic.ini path correctly?

When I run any alembic commands, I get the following error: FAILED: No config file 'alembic.ini' found, or file has no '[alembic]' section According to the documentation, I need to set my path so I did. I'm running WSL Ubuntu 18. Am I setting the…
3
votes
1 answer

Alembic does not generate tables

The first time I run alembic revision --autogenerate -m "init" It generates tables in my database. After I drop the database, remove the versions of the script, and tried to run alembic again. He does not generate anything anymore. I have already…
ivan_filho
  • 1,371
  • 1
  • 10
  • 13
3
votes
1 answer

Alembic generates arbitrary type changes for Geometry columns

I'm working on a project that uses SQLite as a database and Alembic as a database migration tool. It includes spatial data and therefore, spatial extensions and geoalchemy2 are included in the project. I'm using autogenerate command and it detects…
Baris
  • 397
  • 5
  • 12
3
votes
0 answers

database migration using alembic or flask (Python)

i am creating a database using SQLAlchemy and I Need to do Migration to my data as i am using df_sql function for converting my csv into dataframe and then to tables in sqlalchemy. As i do this i need to do Migration to add new column and values…
shankar ram
  • 157
  • 1
  • 13
3
votes
0 answers

Replacing Alembic base revision throws KeyError

I am trying to replace Alembic base revision in a Flask application. The reason is that the Alembic revisions have not been created correctly for this project and I want to make them in correct order from initial database to the latest version. To…
A23149577
  • 2,045
  • 2
  • 40
  • 74
3
votes
2 answers

Flask Migration: Problem creating table and using existing Enum in database. `create_type=False` Do not work

I am using flask-migrate, SQLAlchemy and alembic to manage my database. I want to create a new table in the database. The new table has a column which uses an existing Enum. I have read on many SO questions that you can use an existing Enum with…
DarioB
  • 1,349
  • 2
  • 21
  • 44
3
votes
1 answer

Alembic, SQLAlchemy and multiple "apps" inside a project

Coming to SQLAlchemy from the world of Django, I would like to have a project split into several apps, where models and views are bunched together according to their purpose. For example, I am writing a planner app, I would like to have Users and…
Ibolit
  • 9,218
  • 7
  • 52
  • 96
3
votes
1 answer

Alembic can't drop server_default

I'm trying to add new column to existing table, but getting error when removing server_default. from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision = 'a29663449f3c' down_revision =…
gohxr
  • 101
  • 3
  • 10