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

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, primary_key=True, index=True) name = Column(String) …
Superstars111
  • 25
  • 1
  • 5
0
votes
1 answer

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(length=255), nullable=False), …
Alex
  • 102
  • 2
  • 7
0
votes
1 answer

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 about absolute imports vs. relative imports, but…
Just Me
  • 91
  • 4
  • 12
0
votes
0 answers

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.create_table( 'customer_data', #…
RubyLearning
  • 83
  • 1
  • 7
0
votes
0 answers

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 relation): class…
0
votes
1 answer

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 would do it's job with naming index. So far I have…
mmway
  • 93
  • 1
  • 10
0
votes
0 answers

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(): bar_table = op.create_table( "bars", …
lr_optim
  • 299
  • 1
  • 10
  • 30
0
votes
0 answers

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(Modelpackage): setattr(row, 'description', '') Is…
Mehadi Hassan
  • 1,160
  • 1
  • 13
  • 33
0
votes
0 answers

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 upgrade head on ⬢ my-fastapi-test... up, run.9583 (Free) bash:…
0
votes
1 answer

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'); ^ But on PostgresSQL…
Rodrigo
  • 135
  • 4
  • 45
  • 107
0
votes
1 answer

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 alter a column type of a column that contains data…
stackhatter
  • 304
  • 2
  • 11
0
votes
1 answer

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 database and try to recreate again with the new…
user1204369
  • 299
  • 2
  • 3
  • 10
0
votes
1 answer

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 through Alembic migrations. It can be assumed that…
gmds
  • 19,325
  • 4
  • 32
  • 58
0
votes
1 answer

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 how I organize my project (only list out parts…
pykenny
  • 45
  • 1
  • 5
0
votes
1 answer

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=datetime.datetime.now) updated:…
user13837279
  • 77
  • 1
  • 3