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
27
votes
2 answers

Sqlite lack of ALTER support, Alembic migration failing because of this. Solutions?

I am developing a small registration application for a friend zumba class, using Flask, SQLAlchemy and Flask-migrate(alembic) to deal with db update. I settled on SQlite because the application has to be self contained and runs locally on a laptop…
Kinwolf
  • 755
  • 2
  • 14
  • 24
26
votes
8 answers

No changes detected in Alembic autogeneration of migrations with Flask-SQLAlchemy

I'm having trouble getting Alembic to autogenerate candidate migrations from changes to classes using db.Model (Flask-SQLAlchemy) instead of Base. I've modified env.py to create my Flask app, import all relevant models, initialize the database, and…
PartialOrder
  • 2,870
  • 3
  • 36
  • 44
25
votes
6 answers

Alembic. ModuleNotFoundError in env.py

I have the following project structure --some db: --some db: --alchemy: -- __init__.py --alembic: -- versions -- env.py -- README.py --…
MrOldSir
  • 616
  • 3
  • 9
  • 28
25
votes
4 answers

alembic create_table, check if table exists

I have an alembic upgrade script that creates a table, however I don't want it to create the table if it already exists. According to the alembic doc, I can pass in keyword args to op.create_tables that are acceptable to sqlalchemy.schema.table, so…
mingxiao
  • 1,712
  • 4
  • 21
  • 33
24
votes
3 answers

Modify data as part of an alembic upgrade

I would like to modify some database data as part of an alembic upgrade. I thought I could just add any code in the upgrade of my migration, but the following fails: def upgrade(): ### commands auto generated by Alembic - please adjust! ### …
Peter Smit
  • 27,696
  • 33
  • 111
  • 170
23
votes
2 answers

What is the difference between creating db tables using alembic and defining models in SQLAlchemy?

I could create tables using the command alembic revision -m 'table_name' and then defining the versions and migrate using alembic upgrade head. Also, I could create tables in a database by defining a class in models.py (SQLAlchemy). What is the…
chanchal karn
  • 517
  • 2
  • 7
  • 11
23
votes
4 answers

FAILED: No config file 'alembic.ini' found

I tried to change in Alembic but when I try to run Alembic current I got error. I'm new in alembic, please tell me why I get this error and how can I solve it? I can see alembic.ini in migration folder and also revision identifiers, used by Alembic…
Linda
  • 551
  • 2
  • 7
  • 16
22
votes
1 answer

Postgres and alembic - Assuming SERIAL sequence

I have a postgres DB, which I manage through SQLAlchemy and alembic (for migrations). When creating a DB migration through alembic, I get the following INFO in the console. INFO [alembic.ddl.postgresql] Detected sequence named…
Andrei Cioara
  • 3,404
  • 5
  • 34
  • 62
22
votes
2 answers

Alembic + Sqlalchemy Multi Column Unique Constraint

I'm attempting to create using sqlalchemy a multi column unique constraint that will be picked up by Alembic in it's automatic upgrade script generator. I have create the constraint using: from sqlalchemy import UniqueConstraint in my…
Ansgar S.
  • 221
  • 2
  • 3
22
votes
3 answers

Concurrent db table indexing through alembic script

Is it possible to create concurrent indexes for DB table through alembic script? I'm using postgres DB, and able to create concurrent table indexes through sql command on postgres prompt.(create index concurrently on ();) But couldn't find way to…
user2853625
  • 221
  • 2
  • 4
21
votes
1 answer

Alembic: When autogenerating migrations how to ignore database tables by other products

I am using Alembic to manage migrations for a database. The same database is used by multiple Python packages and each of them have their own migration paths. How I can tell Alembic to ignore tables from other packages when generating automatic…
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
21
votes
4 answers

Alembic migration stuck with postgresql?

I wrote a migration script which works fine on sqlite, but if i try to apply the same to postgres it is stuck forever. With a simple ps i can see the postres stuck on "create table waiting". There are any best practice?
tapioco123
  • 3,235
  • 10
  • 36
  • 42
21
votes
4 answers

Alembic support for multiple Postgres schemas

How can I use Alembic's --autogenerate to migrate multiple Postgres schemas that are not hard-coded in the SQL Alchemy model? (mirror question of SQLAlchemy support of Postgres Schemas, but for Alembic). In particular, we use Postgres schemas to…
dtheodor
  • 4,894
  • 3
  • 22
  • 27
20
votes
4 answers

How to use an existing sqlalchemy Enum in an Alembic migration (Postgres)

At some point in the past I've run an alembic migration which creates a users table like... def upgrade(): ... op.create_table( "users", sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), ... …
Chris W.
  • 37,583
  • 36
  • 99
  • 136
20
votes
4 answers

SQLAlchemy + alembic: create schema migration

I'm not sure how to define a create schema foo migration? My Model looks like this (I'm using Flask-Migrate): class MyTable(db.Model): __tablename__ = "my_table" __table_args__ = {"schema": "foo"} id = ColumnPrimKey() name =…
s5s
  • 11,159
  • 21
  • 74
  • 121
1 2
3
56 57