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

How to set pragma foreign_key=off for database migration only?

I enable foreign key constraint checking via pragma foreign_keys=on in @sqlalchemy.event.listens_for(Engine, "connect") connection handler. I now want to run a database migration which must not have that pragma enabled: def upgrade_database(): …
Raubtier
  • 293
  • 4
  • 8
0
votes
0 answers

Error importing relative package for alembic migration

I have the following directory structure: . └── alembic/ └── migrations/ ├── version/ │ ├── __init__.py │ └── version.py ├── __init__.py └── materialized_views.py I am attempting to import from the…
DougM
  • 920
  • 1
  • 9
  • 21
0
votes
0 answers

How to run Flask cli command with argparse parameters?

I'm using Argparse module to specify which config i should use: python app.py -c cfg/local.yaml If I run Flask db upgrade without -c cfg/local.yaml, it uses my prod config, which is set as default: sqlalchemy.exc.OperationalError:…
0
votes
0 answers

ModuleNotFoundError No module named 'models' occurs when executing alembic upgrade head cmd when trying to deploy docker application under development

I have run the alembic upgrade head using docker. However, I get a models error and cannot run the upgrade head. To solve this, I tried to modify the import statement. But I can't solve it at all. What should I do? .PHONY: alembic.run alembic.run: …
michi
  • 63
  • 1
  • 4
0
votes
1 answer

flask-migrate not detecting existing tables

I followed this tutorial to learn about migrating databases. After running the "flask db init" command the migrations folder is created as expected. However when I run flask db migrate -m 'Initial_Migration' then it doesn't detect the tables in the…
ThaNoob
  • 520
  • 7
  • 23
0
votes
1 answer

Alembic autogenerate recerates existing indexes

I am using a simple mixin for all my tables: class IdMixIn: id = sa.Column(sa.Integer, primary_key=True, index=True) Example table: class MyTable(Base, IdMixIn): __tablename__ = 'my_table' my_col: str = sa.Column(sa.String) I have…
CasualDemon
  • 5,790
  • 2
  • 21
  • 39
0
votes
0 answers

Should I define automatic uuid in alembic migrations?

I have a FastAPI application and in my Item table the field id is an uuid. I'm wondering if I should handle the automatic assigning of id in my models.py or in the Alembic migration file? At the moment this is what I have in my models: class…
lr_optim
  • 299
  • 1
  • 10
  • 30
0
votes
0 answers

multi database migration using alembic sqlalchemy

I have multiple databases like account and meeting. There are relations between tables in different databases e.g. uuid which is present in account database user table has relation to meeting_info table in meeting database. my code structure goes as…
Naveen
  • 91
  • 1
  • 7
0
votes
0 answers

Alembic TypeError: Additional arguments should be named _, got 'nullable'

Hi I added a new model to SQLAlchemy models. But this change trigers this error on all alembic commands Alembic TypeError: Additional arguments should be named _, got 'nullable' My table looks like this: class XClass(Base): …
Michal
  • 112
  • 1
  • 9
0
votes
0 answers

Data Migration approaches with Alembic and SQLAlchemy

I've been fiddling with SQLAlchemy + Alembic for around 2 days and need some guidance. I know Alembic is for schema migrations and the autogenrate stuff is awesome but my question lies now with how do data migrations work? An example: I create a…
0
votes
1 answer

Why Can't I Add a Column using Alembic Because it isn't in the Table?

So I'm trying to use alembic to add a column to my table. Here's my class defining the table with the new line in bold: class Account(db.Model): id = db.Column(db.Integer, index=True, primary_key=True) account_number =…
Ryan
  • 259
  • 3
  • 10
0
votes
1 answer

Upgrade or migrate only single schema using Flask-Migrate(Alembic)

I have a multi-schema DB structure.I am using Flask-Migrate, Flask-Script and alembic to manage migrations.Is there a way to upgrade and perform migrations for only one single schema? Thank you
0
votes
2 answers

How do I cange the string size value for ENUM in Sqlalchemy / PostgreSQL

I am writing a Flask app with SqlAlchemy and PostgreSQL. When I try to enter a value into an enum field that has more than six characters, I get the following error: sqlalchemy.exc.DataError: (psycopg2.errors.StringDataRightTruncation) value too…
Mike C.
  • 1,761
  • 2
  • 22
  • 46
0
votes
0 answers

No migration version file is created in alembic

I use the database on postqres and backends on python and other services. I need to transfer database structure using alembic. Structure of the program: docker-compose.yml: version: "3.9" services: db: container_name: postgresql_db …
0
votes
0 answers

Problems combining my own container and postgre service running together

Hello guys working with pipeline that suppose to run tox (that runs tests, flake, black...). As you can see in my code snipped. I am creating postgres service. Additionally I try to run everything on container…
enigmq
  • 393
  • 5
  • 19