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
1 answer

Running alembic command cause ImportError: cannot import name '_BindParamClause' from 'sqlalchemy.sql.expression'

This happens whenever I ran any alembic command. I am using sqlalchemy version 2.0.3 Traceback (most recent call last): File "", line 1, in File "/home/ado/anaconda3/lib/python3.8/site-packages/alembic/__init__.py", line 8, in…
Bigtymer
  • 121
  • 10
3
votes
0 answers

How to properly type check alembic with mypy

I am using alembic in a project. Everything works as expected, but when checking the types with mypy I am getting: error: Module "alembic" has no attribute "op" [attr-defined] error: Module "alembic" has no attribute "context" [attr-defined] Any…
Imre_G
  • 2,468
  • 1
  • 17
  • 33
3
votes
1 answer

Invalid argument(s) 'render_as_batch'

I'm trying to have Alembic auto-migrate table field type changes in SQLite. According to documentation to do this add render_as_batch=True to the context. Ordinarily, we would need to add compare_type=True but SQLite doesn't support direct type…
phil0s0pher
  • 525
  • 10
  • 21
3
votes
1 answer

Using SQLAlchemy ORM, Pydantic and Alembic: every model change needs to be reflected in THREE separate places, violates DRY?

So I am learning FastAPI and want to get more experience with relational databases. I am using SQLAlchemy ORM, Pydantic and Alembic. Database is Postgres. One thing that I am running into however, is when I want to add a single column to a table I…
RogerKint
  • 454
  • 5
  • 13
3
votes
2 answers

Distribute Alembic migration scripts in application package

I have an application that uses SQLAlchemy and Alembic for migrations. The repository looks like this: my-app/ my_app/ ... # Source code migrations/ versions/ ... # Migration scripts env.py …
Jérôme
  • 13,328
  • 7
  • 56
  • 106
3
votes
1 answer

Better way to generate Postgresql covered index with SQLAlchemy and Alembic

Since Postgresql 11 covered index have been introduced. We create a covered index using INCLUDE keyword like this: CREATE INDEX index_name ON table_name(indexed_col_name) INCLUDE (covered_col_name); Here the official postgresql doc for more…
Rukamakama
  • 780
  • 1
  • 8
  • 16
3
votes
3 answers

Alembic migration with FastAPI + Docker: Connection to port 5432 in localhost fails when I try to run migrations

Currently I am trying to learn about Api development with FastAPI and I am trying to dockerize my project. However, when I try to run the database migrations with alembic in Docker by using docker run sm-api_api alembic upgrade head I get the…
Fre An
  • 33
  • 4
3
votes
1 answer

Pytest Alembic initialize database with async migrations

The existing posts didn't provide a useful answer to me. I'm trying to run asynchronous database tests using Pytest (db is Postgres with asyncpg), and I'd like to initialize my database using my Alembic migrations so that I can verify that they work…
stijndcl
  • 5,294
  • 1
  • 9
  • 23
3
votes
1 answer

Postgres JSONB not compatible with (Sqlite) testing environment

So I am using Postgres for my production database. I use Alembic for migrations and SQLAlchemy to define models and query and so on. This setup works very well for the most part, but I have run into a problem recently. One of my tables requires a…
Eric31
  • 111
  • 8
3
votes
1 answer

Is it possible to drop a unique constraint from a column?

I've tried simply removing the unique=True constraint and running flask db migrate flask db upgrade in the command line but when I run my flask app I'm still getting a (sqlite3.IntegrityError) UNIQUE constraint failed error. Is there a simple way…
kenavuen
  • 51
  • 1
  • 6
3
votes
1 answer

Alembic keeps creating empty migration files even tho there are no changes

I am working on an application using sqlalchemy, postgres and alembic. The project structure is as follows: . ├── alembic.ini ├── main.py ├── migrations │   ├── env.py │   ├── README │   ├── script.py.mako │   └── versions ├── models │   ├──…
singrium
  • 2,746
  • 5
  • 32
  • 45
3
votes
2 answers

Flask Migrate (Alembic) Not Creating Migrations

I have a fairly large Flask app, and my typical workflow to create new data tables is as follows: I create a class in models.py, such as the below: class ExampleModel(db.Model): __tablename__ = 'example_table' id = db.Column(db.Integer,…
3
votes
2 answers

Why is alembic upgrade not working on test database in pytest

I am pretty new to testing in general. I am using postgreSQL and SQLAlchemy for databases, FastAPI backend and Alembic for migrations. I want to set up a test database for testing. I have custom migration scripts that I want to execute on my test…
Shiladitya Bose
  • 893
  • 2
  • 13
  • 31
3
votes
2 answers

Alembic detecting tables that already exits,so it trying to create them again

My model of animation table is below: In the database there are not the test column and I want to update it with alembic. class Animation(Base): __tablename__="Animation" id=Column(Integer,primary_key=True,index=True,autoincrement=True) …
Fatih
  • 99
  • 2
  • 8
3
votes
1 answer

Alembic revision --autogenerate always detects a new table, instead of detecting new columns

For some reason, after adding a new column to a model, alembic's command alembic revision --autogenerate detects a new table and, accordingly, generates a new migration for the whole entity, instead of picking up new columns only. A model's base…
utidevid
  • 393
  • 3
  • 6