Questions tagged [alembic]
Alembic is a lightweight database migration tool for usage with the SQLAlchemy Database Toolkit for Python.
726
questions
0
votes
0
answers
17
views
alembic can not find python-dateutil
I am trying to create a simple migration using
alembic revision -m "ddl for some migration"
and I am getting the following error:
FAILED: The library 'python-dateutil' is required for ...
0
votes
0
answers
26
views
How to disable automatic modifiaction of the database schema in sqalchemy?
When sqalchemy application starts, it automatically modifies database schema, so that database tables would reflect ORM models in python code. In my case it's very unwanted, because when I'm switching ...
0
votes
0
answers
39
views
Problems setting up Alembic with Google Cloud Spanner
I am trying to set up Alembic to work with Google Cloud Spanner, but no matter what I try I end up with one of the following errors when attempting to run a simple "alembic upgrade head":
...
0
votes
0
answers
37
views
Flask-Migrate: column addition apparently undetected, tables recreated instead
I'm using Flask-Migrate in a Flask application with a Postgresql backend. The problem is that after making a change to my models, say a column addition or removal, in any revision or migration that I ...
0
votes
1
answer
66
views
Alembic — store extra information in `alembic_version` table
Is it possible to configure or customise Alembic to store a datetime in the database to record when each migration was run?
The alembic_version table has a single version_num column, which stores the ...
0
votes
0
answers
26
views
alembic executes insert statement without honoring on_conflict_do_update
I have code like this:
from alembic import op
from sqlalchemy.dialects.postgresql import insert
from db.orm.models import Currency
values = dict(key=1, country="USA", currency_code="...
0
votes
0
answers
19
views
Alembic --autogenerate does not detect added column if name is 'external'
I'm adding a field to my SqlAlchemy Base class named 'external' and running
$ alembic revision --autogenerate
But, it is not detecting the added column. If I change the name to 'external_document' (...
0
votes
1
answer
36
views
Can not run migrations with alembic. Socket error
Here i created a User model using sqlmodel.
from sqlmodel import SQLModel, Field, Index
from typing import Optional
class User(SQLModel, table=True):
id: Optional[int] = Field(default=None, ...
0
votes
1
answer
51
views
Alembic & Postgres: how to switch to another schema
I have a postgres database with default public schema, which hosts some tables, including alembic migrations table.
I want a postgres database with an app schema, with all the tables (including ...
0
votes
1
answer
73
views
Python in Maya, syntax error for UV script
I'm trying to assign root UVs to an alembic Maya XGen file, so that I can give the XGen fur the colours of the mesh underneath in Unreal Engine. I have a jaguar mesh with UVs assigned, and am trying ...
0
votes
1
answer
18
views
how to export a alembic file via script in Unity
Is there any way that we can export a alembic file via script, the purpose that I want is store my own data(normals, uv, color ...) to alembic file instead of alembic itself to compute?
0
votes
0
answers
49
views
"VACUUM cannot run inside a transaction block" on postgres, alembic and sqlalchemy
After dropping a big column in Postgres with alembic, I want to clear it's used space so I'd like to run a VACCUM FULL.
When trying to execute the command I get the following error:
sqlalchemy.exc....
1
vote
2
answers
129
views
Alembic migration with FastAPI + Docker: Connection to port 5432 in localhost fails when I try to run migrations
Currently I am trying to learn about Api development with FastAPI and I am trying to dockerize my project. However, when I try to run the database migrations with alembic in Docker by using docker run ...
1
vote
0
answers
31
views
Alembic drops and creates foreign key constraints (autogenerate) when the table has different schema than the referenced columns
I am trying to use the autogenerate feature from alembic to update the schema of a MSSQL database.
class Table1(Base):
__tablename__ = "table1"
__table_args__ = (
...
1
vote
2
answers
38
views
Start from another min value when max value is reached on Postgres Sequence
I have this Sequence defined in sqlalchemy for postgres
import sqlalchemy as sa
user_id_sequence = sa.Sequence(name='user_id_seq',
start=100000,
...
-1
votes
1
answer
35
views
Flask Migrate - IndexError on migration
I'm using Flask Migrate with SQLite3. I have the following upgrade script:
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'e0b1170b3c02'
...
1
vote
1
answer
228
views
Pytest Alembic initialize database with async migrations
The existing posts didn't provide a useful answer to me.
I'm trying to run asynchronous database tests using Pytest (db is Postgres with asyncpg), and I'd like to initialize my database using my ...
0
votes
0
answers
157
views
sqlite3.OperationalError: duplicate column name: operator
I have been following the book of Paul Crickard - "Data Engineering with python". I wanted to install and configure Apache Airflow. After installing it, I tried to initialize the database ...
0
votes
1
answer
36
views
SQLAlchemy not recognising value
I have a bot which uses sqlalchemy to interface with the database. The bot is created using Flask and Twilio and it is connected to an AzureSQL database. When saving a response, I use the code:
db....
0
votes
1
answer
132
views
Alembic loves giving me `RuntimeWarning: coroutine 'connect' was never awaited`
Switched to using SQLAlchemy from TortoiseORM and thought I'd look into Alembic to handle its migrations. After editing the env.py and alembic.ini files I still can't get alembic to generate any ...
0
votes
0
answers
13
views
Customizing sqlalchemy create table DDL for alembic+snowflake
I'm using sqlalchemy declarative models to create my snowflake schema, but since sqlalchemy generates ddl using lower-case identifiers, and snowflake uses upper-case identifiers, alembic can never ...
0
votes
1
answer
60
views
Postgres JSONB not compatible with (Sqlite) testing environment
So I am using Postgres for my production database. I use Alembic for migrations and SQLAlchemy to define models and query and so on. This setup works very well for the most part, but I have run into a ...
0
votes
1
answer
72
views
How to VACUUM a SQLite database from within an Alembic migration?
I am using SqlAlchemy Alembic to perform DB migrations on a SQLite database. One of my migrations removes many redundant records and I would like to VACUUM the database after the deletion.
Here's how ...
1
vote
1
answer
50
views
Alembic 1.8 + DEFERRABLE INITIALLY IMMEDIATE
I am now using Alembic 1.8, SQLAlchemy 1.4 and PostgreSQL
I would like to set my FK constraints as "DEFERRABLE INITIALLY IMMEDIATE".
I passed the FK options as shown below:
sa.Column(
&...
0
votes
1
answer
62
views
SQLAlchemy with MySQL won't auto increment
I'm using MySQL 8.0 and SQLAlchemy. My id column isn't incrementing, and I don't understand why.
SQLAlchemy Model:
class Show(db.Model):
__tablename__ = "shows"
id = Column(Integer, ...
0
votes
1
answer
106
views
How to alter index of a column in alembic
in version: 0001, I create a table users like below:
def upgrade():
op.create_table(
'users',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('email', sa.String(...
0
votes
1
answer
59
views
Python importing files and functions
I have read every tutorial I can find on importing files in Python, and even after following them, my imports don't work. I am getting the error ModuleNotFoundError: No module named 'app.' I have read ...
0
votes
0
answers
25
views
Alembic - Remove legacy table
I am junior dev, I am new at a project. I have to delete a legacy table.
I found it in a migration (created with Alembic):
import sqlalchemy as sa
from alembic import op
def upgrade():
op....
0
votes
0
answers
86
views
Alembic: How to alter column datatype from Enum to Text?
I'm trying to convert a column datatype from an Enum to Text using Alembic with SQLAlchemy PostgreSQL. In my migration file, the upgrade function works perfectly fine and it's able to convert the type ...
0
votes
0
answers
108
views
Problem adding a new column with a foreign key in an Alembic migration with sqlalchemy
I'm having some problems with a db migration when trying to add a new column with a foreign key constraint. Here is the model (the new column is reference_oil and I've also added the oil_ingredient ...
0
votes
0
answers
316
views
Postgres connection string with schema, alembic sqlalchemy
I am working on Alembic with SQLAlchemy on my Alembic.ini I am setting my postgres connection string but it goes to my public schema, i need to choose my schema.
How I can use an specific schema:
...
0
votes
1
answer
86
views
SQLAlchemy create multi column index using naming_convention
I am trying to create multi (i.e. 2-column index) for a model based table. But I'd like not to give specific name for this index. I'd like that naming_convention and alembic revision --autogenerate ...
0
votes
1
answer
71
views
unable to perform flask-migrate migrations on cloud SQL
I am trying to implement flask-migrate with cloud SQL database.
for this, I created a PostgreSQL instance on cloud sql.
following is my app.py file
from flask import Flask
from flask_sqlalchemy ...
0
votes
0
answers
134
views
unable to connect alembic to Cloud sql
I am trying to run alembic on GCP cloud shell and do some basic schema migrations on cloud SQL.
for the setup, I created a MySQL instance on cloud SQL and created a database and user.
I installed ...
0
votes
0
answers
73
views
SQLAlchemy: can I access foreign key object in class method?
I have two classes:
class Foo(SQLModel):
id: str
x: str
y: str
class Bar(SQLModel):
id: str
foo_id: str
z: str
I create a Foreign Key with Alembic migrations like this:
def upgrade():
...
0
votes
0
answers
13
views
How to use a standalone Operations instance and rollback changes?
The Alembic documentation states that "a standalone Operations instance can be made for use cases external to regular Alembic migrations by passing in a MigrationContext". An example is ...
0
votes
0
answers
76
views
Update Postgres String column value without start and end double quotes
In User table the column description column is a string.
But while update that column with empty string '' using sqlalchemy alembic, It will be saved as "".
for row in sa_session.query(...
0
votes
0
answers
554
views
bash: alembic: command not found when migration
I'm trying to make migration to create Tables in my heroku-postgres-database.
I'm using this command:
heroku run "alembic upgrade head"
I got an error after 2 seconds:
Running alembic ...
0
votes
0
answers
28
views
Python. How to import data to Alembic migration
I develop api with Flask, SqlAlchemy, Alembic and other. My project srtucture basic and looks like that :
├───alembic
│ ├───versions
│ ├───first_migration.py
│ ├───second_migration.py
├──...
0
votes
1
answer
24
views
PostgresSQL incompatible query between version 10 and 14
I have the following statement, which runs fine on PostgresSQL version 10
LINE 1: UPDATE tablename SET "cliPrefix"=encode(digest(gen_random_uuid()::text, 'sha512'), 'hex');
...
0
votes
1
answer
53
views
How to alter a column type which contains data using the Alembic API and Oracle Database?
The Alembic API has an alter_column method on the migration context object (https://alembic.sqlalchemy.org/en/latest/ops.html#alembic.operations.Operations.alter_column). However, when I tried to ...
1
vote
1
answer
183
views
GitHub workflows doesn't find a module
I'm trying to configure tests in the GitHub workflows for my FastAPI application. My alembic.ini -file is located in app folder. The alembic ´env.py´ is located in app/alembic.
This is how I try to ...
0
votes
1
answer
89
views
ForeignKey error in ormar has no attribute 'get_column_alias'
I'm testing out ormar to avoid having to create models for both api and database and ran into an issue with foreignkey assignment I can't seem to figure out.
The base code works before I deleted the ...
0
votes
0
answers
124
views
Can two separate sets of Alembic migrations be applied to the same database?
Background: Airflow uses Alembic to apply migrations to the database it uses to store DAG/task metadata. I want to store some other data in this database, and would like to track my schema changes ...
0
votes
1
answer
22
views
Obtain enriched MetaData from Sqlalchemy Model
I'm trying to create a package that manages DB connection, ORM models and migration. It's separated from web service project such as a Flask application, so flask-sqlalchemy is not considered.
This is ...
1
vote
0
answers
20
views
Alembic command.history returning null
According to the alembic documentation, if I want to get the migrations history, I just need to do:
from alembic import command
from alembic.config import Config
alembic_cfg = Config("./alembic....
0
votes
1
answer
90
views
Alembic autogenerate doesn't detect column detect on parent class (Alembic + Ormar ORM)
Here what I want to achieve, I want models common fields inside a base model namely BaseModel as pictured below.
Mixins
class TimeStampMixin:
created: datetime.datetime = ormar.DateTime(default=...
0
votes
0
answers
62
views
Alembic Build Python ORM files from database
I have a database with nearly 100 tables. I am trying to use alembic to manage it in python. Is there a way for alembic to build the ORM python files for me or do I have to write them myself.
For ...
0
votes
0
answers
94
views
Flask Migrate autogenerate revision doesn't work
I've struggled with alembic autogeneration migration using flask migrate.
my modules:
/app/modules/user/modules.py
from sqlalchemy.sql import expression
from app.db import db
class User(db.Model):
...
1
vote
0
answers
34
views
Index a relationship in SQLAlchemy and Almbic
I have two tables like bellow:
Table 1:
class Table1(Base):
__tablename__ = "table1"
id = Column(UUID, primary_key=True)
created_at = Column(DateTime(True), nullable=False, server_default=...