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

SQLAlchemy migrations generating foreign keys with different names. How to drop these?

In my SQLAlchemy data model I had a reference from project->customer. I am doing migrations and initially this FK was created via sa.ForeignKeyConstraint(['customer_id'], ['customers.id'], ) (this was during the same migration that created the…
George Mauer
  • 117,483
  • 131
  • 382
  • 612
1
vote
1 answer

psycopg2.ProgrammingError: relation "event" does not exist

I am using alembic along with flask-migrate along with Postgres for my database. I have ran a db init and db migrate. However when i run the db upgrade command, I get the following error: cursor.execute(statement,…
cp-stack
  • 785
  • 3
  • 17
  • 40
1
vote
2 answers

psycopg2 throws unterminated dollar-quoted string error at or near "$body$"

I'm trying to build an alembic migration revision to create a User Defined Function in PostgreSQL server version 10.2, however the script keeps throwing an error: sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) unterminated…
1
vote
1 answer

Prevent alembic from autogenerating tables

I'm new to so alembic so i might miss a point in its concept but here is the question. i have some sqlalchemy tables in a flask app like this: class Data(Base): __tablename__ = 'Data' __table_args__ = {'schema': 'schema'} id = Column(Integer,…
Florian H
  • 3,052
  • 2
  • 14
  • 25
1
vote
1 answer

Create index with collation

I want to create an index in alembic which will be similar to this: CREATE INDEX my_index ON tab(columnA DESC, columnB COLLATE "da_DK" ASC, id DESC); I know that I can do something like: op.create_index('my_index', 'tab', ['columnA',…
Mariusz
  • 349
  • 2
  • 7
1
vote
1 answer

Alembic: Get SQL output from schema comparison within script

I would like to compare the current db schema with my current model. While compare_metadata gives a nice list of the upgrade operations required, I would also like to print out the associated SQL statements (similar to the offline alembic upgrade…
Matt
  • 11
  • 3
1
vote
1 answer

Alembic shows "empty message" when running upgrade

When I run an Alembic upgrade I see "empty message" next to the revision number instead of "users table". I am following this tutorial. What should appear according to the author: (venv) $ flask db upgrade INFO [alembic.runtime.migration] Context…
Scott
  • 57
  • 7
1
vote
1 answer

Flask migrate doesn't detect models.py

I'm attempting to run flask migrate db in my working directory, and it does not use the model I defined in models.py Here's the code. models.py import sys sys.path.append("../") from Talks2 import db class Talk(db.Model): presenter =…
Josh Gordon
  • 127
  • 2
  • 9
1
vote
0 answers

Flask SqlAlchemy/Alembic migration sends invalid charset to PyMysql

I've spent a 3+ hours on this for 18 of the last 21 days. Please, someone, tell me what I'm misunderstanding! TL;DR: My code is repeatedly sending the db charset as a string to PyMysql, while it expects an object with an attribute called…
1
vote
0 answers

Designing migration scripts to use transactions with Alembic

I've been working on an Alembic upgrade script to use with my SQLAlchemy/SQLite database. The purpose of that script was to change over one column from decimal to integer values. In that process, I learned SQLite doesn't support DROP COLUMN. But…
Lirum
  • 39
  • 6
1
vote
1 answer

Postgres/SQLAlchemy/Alembic change datatype from enum to int and map value with using

I've been using a setup using SQLAlchemy and Alembic migrations together with a Postgres DB in the backend. I've been using enums in some of the DB-Models as datatypes and I've been using the Enum-Type in SQLAlchemy and (because of this) also inside…
Raandom
  • 11
  • 4
1
vote
1 answer

flask-migrate generating unexplained TypeErrors

Flask-Migrate generated a very strange error that I can't decipher. Running flask db init and flask db migrate worked fine, but when I ran flask db upgrade Flask-Migrate stopped on a TypeError on the line sa.PrimaryKeyConstraint('id'). It left this…
qxu21
  • 518
  • 5
  • 11
1
vote
1 answer

Alembic few modules to single database

We need to build a large application that split to multiple modules, App - Module1 --> AppDb - Module2 --> AppDb - Module3 --> AppDb Each module, we would like to add alembic version, all modules connect to single database. But we…
Ry Rith
  • 117
  • 1
  • 10
1
vote
0 answers

Multiple Table Transactions SQLAlchemy

I'm trying to save to two tables. Let say I need to insert to tbl_1 first and use the generated id to be inserted to tbl_2 then after the insert I will call the commit command. On my current approved its like tbl_1.add(data1) tbl_1.commit() --…
MadzQuestioning
  • 3,341
  • 8
  • 45
  • 76
1
vote
1 answer

Running alembic in a python container that depends upon a mysql container

I have a project in which I use the following docker-compose.yml file: version: '3' services: python: restart: always build: ./budget/dockerfiles/python/ ports: - "5000:5000" links: - db …
lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228