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

How can I fix 'greenlet_spawn has not been called' error when using async_sessionmaker with FastAPI and SQLAlchemy?

FastAPI + SQLAlchemy + Alembic + async_sessionmaker not working When "alembic revision --autogenerate' I get an error 'sqlalchemy.exc.MissingGreenlet: greenlet_spawn has not been called; can't call await_only() here. Was IO attempted in an…
sonochiwa
  • 11
  • 3
1
vote
1 answer

local Airflow install & setup: failing at `airflow db init` with `ValueError: No such constraint: 'dag_tag__fkey'`

I'm trying to install airflow 2.6 following the quick start guide here. Installation appears to work fine following the guide above. But when I get to the setup part, specifically the airflow standalone or airflow db init commands, I get the…
Brian Addison
  • 103
  • 1
  • 5
1
vote
0 answers

Alembic revision treats tables as columns

I'm having problem with alembic revision. When running alembic revision --autogenerate, I do receive corrupted schema. Two tables out of 6 are there and there rest is treated as columns. I'm running out of ideas what's wrong. These are my…
kij89
  • 21
  • 2
1
vote
1 answer

alembic_utils create_entity if not exists

Similar to alembic create_table, check if table exists However this question is for creating entities like extensions. The solution for tables using reflection does not appear like it would work for extensions as I don’t see a way to get the list of…
Khorkrak
  • 3,911
  • 2
  • 27
  • 37
1
vote
2 answers

Alembic raises ImportError cannot import name '_NONE_NAME'

When I rebuilt a Docker image for my Python application that uses SQLAlchemy and Alembic, I started getting the following error when running migrations: ImportError: cannot import name '_NONE_NAME' from 'sqlalchemy.sql.naming' I didn't change my…
1
vote
1 answer

Alembic attempts to recreate all tables in the Base class on every migration

In my env.py I have set my target_metadata to Base.metadata which I import from models.py. I have a fresh database with a schema named basic that I want to use to create the tables and setup my models.py like this: from datetime import datetime from…
RogerKint
  • 454
  • 5
  • 13
1
vote
0 answers

SqlAlchemy, AttributeError: after_update

Hi guys I have 3 Tables (Traces, Components, Datasets) In the Traces table, I am trying to add an event where if the dataset_id is set to be NULL the active_columns will automatically be set to Null. this is the code I have: from datetime import…
Matan
  • 73
  • 2
  • 14
1
vote
0 answers

How to use functions like op.add_column and op.alter_column from alembic, but without the whole alembic environment?

I try to use alembic functions but without the whole environement from alembic (ini, env.py, etc). It worked until I wanted to use the op-method-calls like op.add_column and op.alter_column. Then I got always this Error: NameError: Can't invoke…
selinski
  • 13
  • 4
1
vote
1 answer

fastapi alembic exclude celery tables

My postgres database already includes celery backend tables (celery_taskmeta and celery_tasksetmeta) and when i use the following command: alembic revision --autogenerate -m "some message" the generated file includes dropping these tables in upgrade…
1
vote
0 answers

Why does alembic find an update using autogenerate

I am using alembic to manage my database migrations. In my last revision, I realized that alembic identify a difference in one of my id column, and I don't understand why. Here is the result of the alembic revision --autogenerate -m "update" command…
samuel guedon
  • 575
  • 1
  • 7
  • 21
1
vote
1 answer

Unable to set cloud spanner dialect for Alembic

I have installed the following packages - SQLAlchemy==1.4.41 sqlalchemy-spanner==1.2.2 alembic==1.8.1 Then I created a file main.py where I am creating a SQLAlchemy engine for cloud spanner. from sqlalchemy import create_engine, MetaData from…
Jeet Patel
  • 1,140
  • 18
  • 51
1
vote
1 answer

alembic revision --autogenerate more than one script.py.mako file

I have simple case i.e, one database. At times, I want to generate a revision using different script.py.mako file (or different content). Is it possible to support more that one script.py.mako file and specify in command not to use default…
1
vote
0 answers

Alembic autogenerate not working for table modifications when run programmatically

I'm trying to create automatic tests for alembic, specifically to test that the revision --autogenerate command provides the expected migrations. Instead of running from the command line, I want to obtain the suggested revisions programmatically and…
1
vote
0 answers

How should `USING start_time::timestamp without time zone` be specified in Flask SQLALchemy?

My objective was to alter a column's data type from String to DateTime in Flask using Flask SQLAlchemy. This is the model in question: class Show(db.Model): id = db.Column(db.Integer, primary_key=True) venue_id = db.Column(db.Integer,…
1
vote
0 answers

sqlalchemy, alembic with postgres and postgis drop tables in other schema

I'm working with Alembic with SQLAlchemy and I'm a newbie with Python. Database: postgres with with postgis (with tiger schema and others) I created a class into models.py file that define my tables. class Adv(Base): __tablename__ = 'advs' …
Luca Rasconi
  • 1,085
  • 11
  • 30