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

Getting Flask-Migrate to Ignore SQL Views that are mapped as Flask-SQLAlchemy Models

I am using Flask-SQLAlchemy to define my models, and then using Flask-Migrate to auto-generate migration scripts for deployment onto a PostgreSQL database. I have defined a number of SQL Views on the database that I use in my application like below.…
Andy G
  • 820
  • 1
  • 8
  • 11
4
votes
1 answer

Run alembic migrations on a flask elastic beanstalk instance

I have an elastic beanstalk instance with flask installed. I have alembic properly setup and I can run the command locally by running cd migrations alembic upgrade head I made a file in my .ebextensions which looks like this: container_commands: …
4
votes
1 answer

Is it possible to retrieve metadata object in alembic migration?

I need to migrate schema & data. I would like to organize it as described below. But sqlalchemy.Table requires Metadata object. Is it possible to retrieve it from alembic? metadata = op.get_metadata() # how i can do this? table =…
avasin
  • 9,186
  • 18
  • 80
  • 127
4
votes
0 answers

Autocomplete Alembic Commands

Is there any way to add alembic commands to the bash so that the alembic command autocomplete works like git? For example, in Quick Tip: Autocomplete Git Commands and Branch Names in Bash the author shows how to add git commands to .bash_profile how…
Max
  • 2,425
  • 6
  • 35
  • 54
4
votes
1 answer

SQLAlchemy, Alembic and new instances

In a platform using Flask, SQLAlchemy, and Alembic, we constantly need to create new separate instances with their own set of resources, including a database. When creating a new instance, SQLAlchemy's create_all gives us a database with all the…
RobertoCuba
  • 881
  • 9
  • 25
4
votes
0 answers

Use Alembic to upgrade in-memory sqlite3 database

I have a Flask app created with an app factory. When testing with pytest, I want to use an in-memory sqlite database because it is much faster than using temporary files. I'm using Flask-Migrate to integrate Alembic and Flask-SQLAlchemy. …
user178921
  • 64
  • 8
4
votes
1 answer

alembic distribution was not found error

I am using alembic with virtualenv in a django project, I have created a virtual environment in path /ENV /myproject inside my project I have a configs/development.ini file in which I define alembic parameters script_location =…
user3814030
  • 1,263
  • 3
  • 20
  • 37
4
votes
1 answer

How do I test an alembic migration when I wish to alter the data via Session objects inside the upgrade?

I am trying to get alembic to do a database migration for me. I have made changes to my model which add two new columns, which will have data that is calculated based on the current rows in the table. What I really want to do is figure out how to…
Peter Grace
  • 569
  • 5
  • 20
4
votes
2 answers

Flask-Migrate "No section: 'alembic'" on "db migrate" command

I'm using Flask-Migrate, and I'm trying to add a column to my database by using the db migrate command. Here is the setup: from flask import Flask, render_template, request, session, flash, redirect, url_for from flask.ext.babel import Babel from…
b_g
  • 299
  • 1
  • 4
  • 14
4
votes
1 answer

"Directory migrations already exists" during init on Heroku

I ran the command heroku run init and got this error. How can I fix it? manager.run() File "/app/.heroku/python/lib/python2.7/site-packages/flask_script/__init__.py", line 412, in run result = self.handle(sys.argv[0], sys.argv[1:]) File…
LiLi
  • 301
  • 2
  • 7
  • 21
4
votes
1 answer

Alembic migration issue with PostgreSQL schema and invalid one-to-many relationship

I've created a database and schema in Postgres. I have my models and when I run python manager.py db migrate which uses Flask-Migrate, I get the error below. However, the db init command works. sqlalchemy.exc.ProgrammingError: (ProgrammingError) no…
darksky
  • 20,411
  • 61
  • 165
  • 254
4
votes
1 answer

alembic create_table using declarative_base derived objects

I have an Alchemy ORM object: from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class MyORM(Base): id = Column(Integer, primary_key=True) name = Column(String(128), unique=True, nullable=False) When using…
ezdazuzena
  • 6,120
  • 6
  • 41
  • 71
4
votes
1 answer

alembic and getting the last inserted value

I'm using alembic to manage my database structure. After adding a table using id as Integer and primary key the id column will be an autoincrement-column. How do I query the data in the upgrade script so I'm sure that I get the correct id (I know…
Asken
  • 7,679
  • 10
  • 45
  • 77
4
votes
3 answers

How to turn on 'PRAGMA foreign_keys = ON' in sqlalchemy migration script or configuration file for sqlite?

In a suitable sqlite version, we can enforce foreign key constraint by 'PRAGMA foreign_keys = ON'. However user can not log in a database every time when making a connection. So I wonder how can we make it working in a migration script in…
user1342336
  • 967
  • 2
  • 16
  • 28
3
votes
0 answers

How can I run an alembic migration on an aurora serverless v1 postgres from an ecs task?

I have an ecs task which is meant to run a database schema migration on an aurora serverless v1 in aws. According to most of the examples I've seen, the connection is enabled by saving the database url with the username and password in the alembic…