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

How to squash/split SQLAlchemy migrations files for minimal service downtime?

I have a SQLAlchemy/Flask application that is being accessed publicly by millions of people. Every 2 weeks, I release a new version of this application and I run database migrations using python manage.py db upgrade. This runs any new migration…
Saqib Ali
  • 11,931
  • 41
  • 133
  • 272
2
votes
0 answers

Alembic log files

I'm trying to run a basic alembic script that creates a table on localhost revision = '43a24caf4e92' down_revision = 'b61a0e474ffd' from alembic import op import sqlalchemy as sa def upgrade(): op.create_table( 'crawl', …
Arun
  • 1,599
  • 5
  • 19
  • 33
2
votes
1 answer

Flask-migrate makes SQLite migration instead of PSQL

Hi I've exported in virtualenv database with command export DATABASE_URL="postgresql://localhost/dbname" But after running python manage.py init and python manage.py db migrate Result is: INFO [alembic.runtime.migration] Context impl…
rhb
  • 21
  • 2
2
votes
2 answers

Alembic not generating correct changes

I am using Flask-Migrate==2.0.0. Its not detecting the changes correctly. Every time I run python manage db migrate it generates a script for all models although they have been added successfully in previous revisions. I have added two new columns…
Waseem
  • 1,392
  • 5
  • 21
  • 30
2
votes
1 answer

flask migrate upgrade not working after drop table

I am using SqlAlchemy and Flask-migrate for DB migration. I have successfully init the DB and upgrade once using the following: python manage.py db init python manage.py db migrate # creates the migration script,faefc6a6c7ae, as below:…
qre0ct
  • 5,680
  • 10
  • 50
  • 86
2
votes
1 answer

Set the different value of column when upgrading table with alembic

I am using PostgreSQL and Alembic for migration. When I added new column to my User table Alembic generated migration with the following script: from alembic import op import sqlalchemy as sa import random def generate_toke(): return…
bin381
  • 342
  • 1
  • 4
  • 14
2
votes
1 answer

Flask-Migrate having issue with enum class in models

Using flask-migrate before I was able to create enums by using flask-sqlalchemy's db.Enum and entering the values in as strings like so. reservation_status = db.Enum('pending', 'confirmed, name='reservation_status_enum') I decided to start using…
2
votes
1 answer

Flask-SQLAlchemy uses SQLite database even though it's configured for PostgreSQL

I have a Flask app with a PostgreSQL database on Heroku. I am trying to run the migrations that I created to migrate our staging database by using the heroku run command. However, I get an error that the SQLite dialect can't render a JSON type. …
tonestrike
  • 320
  • 6
  • 22
2
votes
1 answer

How to sync db with Flask-Migrate in a fresh application deployment?

When deploying an application to a fresh server (i.e. the database is empty) how do I sync the database properly with Flask-Migrate? I've added Flask-Migrate to the project when I already had some schema in place so I don't have "initial"…
Warwick
  • 1,200
  • 12
  • 22
2
votes
2 answers

Alembic migration to convert serial field to integer

I initially defined one of my SQLAlchemy models as: class StreetSegment(db.Model): id = db.Column(db.Integer, autoincrement=True) # surrogate ID seg_id = db.Column(db.Integer, primary_key=True) # assigned in another system; don't…
serverpunk
  • 10,665
  • 15
  • 61
  • 95
2
votes
1 answer

Inserting Unicode values on alembic migration

I'm working on a small pet-project that involves some accounting in multiple currencies. During its development I decided to move from straight-forward DB setting to DB-migrations using alembic. And on some migrations I need to populate DB with…
wanderlust
  • 1,826
  • 1
  • 21
  • 25
2
votes
0 answers

alembic autogenerate produces all tables, when head revision already contains them

If I do these series of commands in Alembic the result doesn't make sense to me. I would expect that the autogenerated migration would be empty as I changed nothing in the database between invocations. Is my understanding incorrect? I assumed…
Angelo
  • 786
  • 8
  • 8
2
votes
1 answer

type modifier is not allowed for type "geometry" when updating DB with postgis via geoalchemy2 & alembic

My alembic update script for adding a new postgis geometry point looks like this: from alembic import op import sqlalchemy as sa import geoalchemy2 as ga def upgrade(): op.add_column('stuff', sa.Column('my_location', ga.Geometry('POINT',…
user1561108
  • 2,666
  • 9
  • 44
  • 69
2
votes
0 answers

Flask-Migrate: Data migrations do not aplly after schema migrations together

At first I create schema migration with Flask-Migrate (Alembic migrations for Flask). After that, I create separated data migration script (with Flask-Migrate too). But when I run ./manage db upgrade for apply all not-applied migrations, I see in…
2
votes
1 answer

Error while trying to migrate database (slalchemy, slqite3)

I have the next models.py file: from app import db, bcrypt from sqlalchemy import ForeignKey from sqlalchemy.orm import relationship class BlogPost(db.Model): __tablename__ = "posts" id = db.Column(db.Integer, primary_key=True) title…
Gerardo Tarragona
  • 1,185
  • 4
  • 15
  • 28