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

Alembic API how to get raw SQL script

My requirement is to generate a SQL script and upload that script to cloud storage. I'm using Alembic Command to generate SQL script. command.upgrade(alembic_cfg, revision='a:b', sql=True) The command.upgrade function prints the SQL script into the…
rebornx
  • 407
  • 6
  • 21
2
votes
1 answer

SQLAlchemy date field not updating with server_onupdate

Using SQLAlchemy with flask_sqlalchemy and alembic for PostgreSQL. I have the following definition for a field: date_updated = db.Column(db.DateTime, server_default=db.func.now(), server_onupdate=db.func.now()) However the field never updates when…
Greg Butler
  • 103
  • 6
2
votes
1 answer

Removing un-named unique constraint

I'm using Alembic with Flask-SQLAlchemy, and I'm trying to remove a unique constraint on a column in one of my tables. Looking over the migrations - this constraint was never named: sa.UniqueConstraint('title'), obviously when I update the model,…
m0ngr31
  • 791
  • 13
  • 29
2
votes
1 answer

How to use existing postgres enum in alembic migration?

I have a new migration using alembic. My database has a enum name myenum. This is the migration script: def upgrade(): op.create_table( "test_table", # ... sa.Column("enum_col", sa.Enum("A", "B", "C", name="myenum"),…
PaxPrz
  • 1,778
  • 1
  • 13
  • 29
2
votes
2 answers

How to specify fillfactor for a table in sqlalchemy?

Let's say I have a simple table. In raw SQL it looks like this: CREATE TABLE events (id INT PRIMARY KEY) WITH (fillfactor=60); My question is how to specify fillfactor for a table using sqlalchemy declarative base? Of course I can achieve that by…
Ivan Vinogradov
  • 4,269
  • 6
  • 29
  • 39
2
votes
0 answers

How to get a predictable column order in alembic migration

I am using Alembic with SqlAlchemy to autogenerate migrations. The column order in the migration file doesn't always match the order in the SqlAlchemy classs. Is there a way to ensure this. Example I started with a class like this class…
sea
  • 199
  • 2
  • 9
2
votes
1 answer

Can't connect flask sqlAlchemy to the mysql database

I'm trying to connect my flask app with the MySQL database. here's MySQL data mysql> select user(); +----------------+ | user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.01 sec) mysql> SHOW…
HASKA
  • 61
  • 1
  • 6
2
votes
1 answer

Alembic online mode FATAL: database does not exist

I am using alembic and when I run alembic upgrade head It returns: sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL: database "my_db'" does not exist My config file has the following url: sqlalchemy.url =…
mrc
  • 2,845
  • 8
  • 39
  • 73
2
votes
0 answers

How to solve "sqlalchemy.exc.OperationalError" when using Alembic

I want to add columns to a table in my database dynamically since I don't want to have to specify all columns when I set it up in the class In order to solve this I am instead using alembic to add columns to a table but I am having problems. In…
user12288003
  • 199
  • 1
  • 4
  • 14
2
votes
0 answers

Adding an ArrayOfEnum column to table with alembic

I have defined an 'ArrayOfEnum' type as described here: https://docs.sqlalchemy.org/en/13/dialects/postgresql.html The upgrade function in my version file contains the following code: op.add_column('example_table_name',…
Noam A
  • 53
  • 4
2
votes
1 answer

TypeError: can only concatenate list (not "str") to list | Alembic Migration

I am trying to run a migration to add a foreign key constraint. This is when I try to add a artist_id to my RSVP model on a many to one relationship. Each RSVP can only have an artist, and an artist can have many rsvps. Here is my migration code def…
2
votes
1 answer

How to add new dialect to Alembic besides built-in dialects?

Alembic support 5 built-in dialects only: https://github.com/sqlalchemy/alembic/tree/master/alembic/ddl Now I want to manages schema in Apache Hive via alembic and noticed that PyHive supports SQLAlchemy interfaces so technically Alembic can support…
shawnzhu
  • 7,233
  • 4
  • 35
  • 51
2
votes
2 answers

python database migration on application startup

I am currently developing a new app against postgresql. For ORM and migrations I thought to use SQLAlchemy with alembic. As I would like to handle migrations on application startup I wondered if there are any python projects (like FlyWay + Spring…
René Jahn
  • 1,155
  • 1
  • 10
  • 27
2
votes
1 answer

How do I properly edit Alembic migration scripts in Flask-Migrate/Flask-SQLAlchemy to add or edit columns?

I have a little app I'm using to scrape data from online articles. Currently, I am trying to figure out how to edit the migration scripts from Flask-migrate so I don't have to delete all the migration data and the SQlite database then re-scrape the…
2
votes
1 answer

Alembic recreates foreign keys every time I migrate causing duplicate foreign keys on my tables

I have a flask app using sql-alchemy and flask migrate to handle database changes. Every time I run a flask migrate to create a script for Alembic to update the database, the script contains commands to create foreign keys that already exist in my…