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
2 answers

Flask migrate error - foreign key associated with column could not find table with which to generate a foreign key to target column

I have two models as following in different files. When I run flask db migrate I get this error. raise exc.NoReferencedTableError( sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column 'datasets.user_id' could not find table…
aysberna
  • 58
  • 8
1
vote
0 answers

Using Alembic only scan through one table

I have multiple databases, I am using alembic to maintain the migrations for these database. However I am currently using older version of alembic (Version 1.6.5) I am trying to upgrade to a latest version of alembic as it supports…
nardowick
  • 101
  • 1
  • 3
1
vote
0 answers

Why does python alembic postgres migration leave locks that prevent future migrations?

I have a psql database that I want to do alembic migrations on. After the migrations, locks are still present: SELECT l.pid, l.locktype, l.mode FROM pg_locks l INNER JOIN pg_stat_activity s ON (l.pid = s.pid) where usename='migrations_user'; pid …
swagrov
  • 1,510
  • 3
  • 22
  • 38
1
vote
0 answers

Alembic migrations in docker-compose

I have a FastAPI application which uses ormar orm and alembic for db migrations. When I migrate my changes to db everything is working but alembic versions that stored inside my container alembic directory won't be stored in my local alembic…
Mojtaba Arezoomand
  • 2,140
  • 8
  • 23
1
vote
0 answers

Using alembic to migrate pre-existing and populated tables

I have this tables I created models for using vanilla SQLAlchemy to operate the postgre DB. class table: def __init__(self): self.engine = create_engine(DB_ADDRESS, poolclass=NullPool) self.meta = MetaData() self.table = Table( …
gsab
  • 11
  • 4
1
vote
2 answers

In python pyramid web framework, how can I drop all db table rows before seeding?

I am using a cookiecutter to make a pyramid web app. It has a function to seed the db…
spacether
  • 2,136
  • 1
  • 21
  • 28
1
vote
0 answers

FastAPI Alembic - migrations files are not being created even though output says so. Folder "versions" is empty, and tables are missing from database

I wanted to incorporate Postgresql into my FastAPI API. After a research I decided to follow this tutorial - https://youtu.be/NH4VZaP3_9s And full code can be found here - https://github.com/veryacademy/YT_FastAPI_Beginner_Fast-Track I checked…
Peksio
  • 525
  • 6
  • 25
1
vote
0 answers

Alembic migrate as_uuid for UUIDField

I'm trying to migrate a SQLAlchemy model (using Flask-SQLAlchemy if that helps). I use a model that looks like this: class Model: uuid = db.Column(UUID(as_uuid=True)) # With an occasional foreign key class Model1: …
AOL
  • 31
  • 1
  • 5
1
vote
0 answers

Alembic: AttributeError: 'RedshiftDDLCompiler' object has no attribute 'visit clause'

I have this issue when I try to run upgrade on a migration that will change the type of a VARCHAR column to INTEGER and change the PK too. This is traceback: The definition of the class is the follow: class ActionsIntiza(Base): __tablename__ =…
Juan Almada
  • 129
  • 7
1
vote
1 answer

Can I use alembic autogenerate with Peewee ORM?

I used Alembic with SQL alchemy, and the autogenerate option worked great. In my new company, we use Peewee as ORM. Is it possible to make Alembic autogenerate work with Peewee as well? I looked in the…
Oded BD
  • 2,788
  • 27
  • 30
1
vote
0 answers

Override or create new engine in Flask-Migrate migration

I'm running a migration which inserts ~160k records into a PostgreSQL database. This is taking between 40-50 seconds to complete. Unfortunately, this breaks the build process in CircleCI and therefore makes every build after it fail. I also have no…
kenshin23
  • 129
  • 13
1
vote
0 answers

DRYer way to use SQLAlchemy and alembic

I am starting building an application using SQLAlchemy as the ORM. Initially i have defined 18 data models which I know I will need. They range in size from 3 columns to 30+ columns. Following the SQLAlchemy and alembic documentation i can see to…
teebagz
  • 656
  • 1
  • 4
  • 26
1
vote
2 answers

alembic autogenerates creates empty migration but generates table

I followed the documentation from Alembic to auto-generate migrations. My project structure looks like this: alembic/ versions/ env.py README script.py.mako data/ __init__.py db.py models.py alembic.ini app.db I made changes to env.py…
Tyrion
  • 405
  • 8
  • 22
1
vote
0 answers

Point to the location of the alembic.ini file to the python file

I wanted use alembic.ini file in my python. That is I wanted to show the compiler that my .ini file is locating in this place. My project struture is | my_project/ | migrations |alembic.ini |versions |xxxxxx_.py …
vaanumalar
  • 57
  • 1
  • 11
1
vote
1 answer

How do I set up Alembic for a SQLite database attached as a schema?

I've tried many contortions on this problem to try to figure out what's going on. My SQLAlchemy code specified tables as schema.table. I have a special connection object that connects using the specified connect string if the database is PostgreSQL…
phrodod
  • 156
  • 1
  • 8