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

621 questions
115
votes
3 answers

How do I execute inserts and updates in an Alembic upgrade script?

I need to alter data during an Alembic upgrade. I currently have a 'players' table in a first revision: def upgrade(): op.create_table('player', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name',…
Arek S
  • 2,913
  • 4
  • 19
  • 29
113
votes
11 answers

Target database is not up to date

I'd like to make a migration for a Flask app. I am using Alembic. However, I receive the following error. Target database is not up to date. Online, I read that it has something to do with this.…
GangstaGraham
  • 7,425
  • 11
  • 39
  • 54
80
votes
11 answers

Is it possible to store the alembic connect string outside of alembic.ini?

I'm using Alembic with SQL Alchemy. With SQL Alchemy, I tend to follow a pattern where I don't store the connect string with the versioned code. Instead I have file secret.py that contains any confidential information. I throw this filename in my…
Doug T.
  • 59,839
  • 22
  • 131
  • 193
62
votes
3 answers

Alembic: IntegrityError: "column contains null values" when adding non-nullable column

I'm adding a column to an existing table. This new column is nullable=False. op.add_column('mytable', sa.Column('mycolumn', sa.String(), nullable=False)) When I run the migration, it complains: sqlalchemy.exc.IntegrityError: column "mycolumn"…
Ron
  • 5,778
  • 9
  • 33
  • 39
55
votes
13 answers

Altering an Enum field using Alembic

How can I add an element to an Enum field in an alembic migration when using a version of PostgreSQL older than 9.1 (which adds the ALTER TYPE for enums)? This SO question explains the direct process, but I'm not quite sure how best to translate…
bboe
  • 3,510
  • 1
  • 24
  • 39
54
votes
4 answers

Creating seed data in a flask-migrate or alembic migration

How can I insert some seed data in my first migration? If the migration is not the best place for this, then what is the best practice? """empty message Revision ID: 384cfaaaa0be Revises: None Create Date: 2013-10-11 16:36:34.696069 """ #…
Mark Richman
  • 26,790
  • 23
  • 85
  • 150
53
votes
3 answers

alembic util command error can't find identifier

I'm trying to use alembic to handle local migrations on my project. It worked the first time, but then I needed to delete the folder and restart.(don't ask why, I just had to) I'm following this tutorial and I run the command python manage.py db…
53
votes
9 answers

Using Alembic API from inside application code

I am using SQLite as an application file format (see here for why you would want to do this) for my PySide-based desktop application. That is, when a user uses my app, their data is saved in a single database file on their machine. I am using the…
John David Reaver
  • 958
  • 1
  • 8
  • 17
52
votes
1 answer

Undo last Alembic migration

I created a migration with alembic revision --autogenerate, applied it to my development database with alembic upgrade head, and then realised it wasn't quite what I wanted. How can I revert the migration so that I can tweak it and try again?
Mark Amery
  • 110,735
  • 57
  • 354
  • 402
43
votes
1 answer

sqlalchemy : executing raw sql with parameter bindings

I'm trying to run this simple raw sql statement with parameters with SQLALchemy (within an alembic script) : from alembic import op t = {"code": "123", "description": "one two three"} op.execute("insert into field_tags (id, field_id, code,…
Max L.
  • 8,994
  • 12
  • 49
  • 80
37
votes
2 answers

Alembic: alter column type with USING

I'm attempting to use alembic to convert a SQLAlchemy PostgreSQL ARRAY(Text) field to a BIT(varying=True) field for one of my table columns. The column is currently defined as: cols = Column(ARRAY(TEXT), nullable=False, index=True) I want to change…
bard
  • 2,440
  • 5
  • 29
  • 44
37
votes
4 answers

alembic revision - multiple heads (due branching) error

I've got an application and I wanted to create a new migration for it today. When I run $ alembic revision -m "__name__" I got a message Only a single head is supported. The script directory has multiple heads (due branching), which must be…
Arek S
  • 2,913
  • 4
  • 19
  • 29
37
votes
8 answers

sqlalchemy.exc.ArgumentError: Can't load plugin: sqlalchemy.dialects:driver

I am trying to run alembic migration and when I run alembic revision --autogenerate -m "Added initial tables" It fails saying sqlalchemy.exc.ArgumentError: Can't load plugin: sqlalchemy.dialects:driver the database url is…
daydreamer
  • 73,989
  • 165
  • 410
  • 667
33
votes
4 answers

How to import the own model into myproject/alembic/env.py?

I want to use alembic revision --autogenerate with my own model classes. Because of that I need to import them in myproject/alembic/env.py as described in the docs. But this doesn't work even if I tried a lot of variations. I am not sure in which…
32
votes
2 answers

Can Alembic Autogenerate column alterations?

I was able to use alembic --autogenerate for when adding / removing columns. However, when I wanted to modify for example a "url" column from 200 characters to 2000 characters, it doesn't detect the change. How can I make Alembic (using…
Dexter
  • 5,536
  • 13
  • 67
  • 94
1
2 3
41 42