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

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 example in the database there is a user table with…
Nick
  • 46
  • 4
0
votes
1 answer

Why is nullable field required with sqlalchemy

I'm trying to use Alembic's bulk_insert in the migration file to get some data to my database for testing purposes. This is my database creation code: import sqlalchemy as sa from alembic import op def upgrade(): test_table = op.create_table( …
lr_optim
  • 299
  • 1
  • 10
  • 30
0
votes
1 answer

alembic alter_column with existing primary key constraint

I need to alter the type of a column with alembic. Currently my code looks like this: with op.batch_alter_table('annotations', schema=None) as batch_op: batch_op.alter_column('anno_id', existing_type=sa.Integer(), type_=sa.String(36)) …
Robert Sim
  • 1,428
  • 11
  • 22
0
votes
1 answer

CreatedAt mixin (base class) in python SQLModel

I'm using SQLModel and would like to define base class with created_at field to inherit from it in others models. class CreatedAtMixin(SQLModel): created_at: datetime = Field(default=datetime.now(timezone.utc), nullable=False) But when i'm…
Nikita
  • 376
  • 1
  • 10
0
votes
2 answers

flask-migrate/alembic - how to skip a specific sqlalchemy bind

Is there any way to skip a bind using flask db migrate / alembic? I have two repos which have SQLALCHEMY_BINDS which use a common database, but otherwise the databases are different. In my case members repo uses db members,…
Lou K
  • 1,128
  • 2
  • 12
  • 31
0
votes
1 answer

Using the Alembic bulk_insert function only when the table is empty

At the moment I'm using Alembic to create a SQLite database. Now I have a table that needs default data when creating the table. The issue I found the bulk_insert function that allows you to insert data on upgrades and downgrades. The problem I am…
0
votes
1 answer

How to make alembic or flask migrate name foreign keys when autogenerating migrations?

I've been struggling with this issue on and off for quite some time, and strangely could not find a straightforward question/answer combo on this on SO. Related questions here and here. I finally found a solution so I will ask and answer my own…
Willow
  • 1,132
  • 5
  • 20
0
votes
1 answer

I ma trying to use alembic with fastapi and postgres sql but it gives me error that No module named 'database but it existing in the project

it gives me this error when I am running the alembic --autogenerate command. it gives the error that No module name database found but database.py file exist and it gives this error. this is my env file and an error is occurring due to this file…
0
votes
0 answers

How to add index to existing column using alembic

Im new to python alembic .want to add index to existing column in particular table i did that but struck in creating alembic file for that. ex: class File(db.model): __tablename__ = 'file' id =…
0
votes
1 answer

Use alembic migration or docker volumes to populate docker postgres database?

I believe this question already shows that I am new to docker and alembic. I am building a flask+sqlalchemy app using docker and postgres. So far I am not using alembic, but I am about to plug it in and some questions came up. I will have to create…
Joaquim
  • 111
  • 1
  • 10
0
votes
0 answers

Can't figure out DeclarativeMeta error with alembic and sqlalchemy in django project

I could use some help figuring out how to debug this: I suspect that there is something wrong with my models.py file but the error messages are pretty vague. Using Alembic and sqlalchemy instead of Django ORM (relatively new to all the above) and…
Justin Benfit
  • 423
  • 3
  • 11
0
votes
2 answers

Error: trying to push Table SQLAlchemy models to my production heroku-server using Alembic

I am trying to push my SQLAlchemy-models to create Tables in my heroku-postgres-database. I use this command: heroku run alembic upgrade head It starts to Run as expected. But after a while I just get error, Bash: alembic: command not found. How…
0
votes
0 answers

Set value for new column in DB

I am using flask-migrate to handle migrations. After adding a new column to the db and running the migration, what is the best approach to set the value of the new column for old users? Right now I am temporarily adding this snippet for a url: def…
ElLorans
  • 56
  • 5
0
votes
2 answers

flask alembic: avoid check DB revision ID

I am deploying a Flask-based app based on this amazing tutorial. I deploy my DB through: flask db init flask db migrate flask db upgrade sometimes it checks for older version of the DB inside migrations directory and I get this error (full log…
cccnrc
  • 1,195
  • 11
  • 27
0
votes
1 answer

How do I drop geospatial metadata tables in SpatiaLite SQLite database?

SpatiaLite includes a function for standing up geospatial functionality in an existing SQLite database, namely, InitSpatialMetaData(). I'm seeking a similar method for tearing down geospatial metadata tables, and associated triggers and views,…
ryangooch
  • 54
  • 3