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

Alembic and enum type

Why the following code dont work? new_type = sa.Enum('nonexistent_executable', 'output_limit_exceeded', 'signal', 'success', 'timed_out', name='status') old_type = sa.Enum('nonexistent_executable', 'signal', 'success', 'timed_out', …
tapioco123
  • 3,235
  • 10
  • 36
  • 42
3
votes
1 answer

alembic migration error flask

I am making a test blog using the guide found here. It's pretty comprehensive. However, I'm having trouble with the alembic migrations. I can erase all the versions, and spin up a new database with all of the columns just fine. But, when I add a new…
user2497586
3
votes
1 answer

Alembic drops indexes for foreign keys

I have a column address_id = db.Column(db.Integer, db.ForeignKey(Address.id, ondelete='CASCADE'), index=True). Autogenerating a migration with Alembic always adds a drop_index operation. op.drop_index('address_id', 'companies') Why does this happen…
Viorel
  • 1,420
  • 1
  • 17
  • 27
3
votes
1 answer

Alembic bulk_insert to table with schema

I'm looking at the example at bulk_insert. # Create an ad-hoc table to use for the insert statement. accounts_table = table('account', column('id', Integer), column('name', String), column('create_date', Date) ) I would like to bulk…
Asken
  • 7,679
  • 10
  • 45
  • 77
3
votes
2 answers

Alembic Django Flask migrate database

I have a database shared between django and flask. In flask app, I use sqlAlchemy and use Alembic to migrate database. But when I migrate database and use command: $ alembic revision --autogenerate -m "some message" It will automatically remove all…
web_dev
  • 41
  • 1
  • 5
3
votes
1 answer

alembic: use subquery for update statement in migration

I'm using alembic to manage my database migrations. In my current migration I need also to populate a column based on a SELECT statement (basically copying a column from a different table). With plain SQL I can do: UPDATE foo_table SET bar_id= …
Felix Schwarz
  • 2,938
  • 4
  • 28
  • 41
2
votes
2 answers

sqlalchemy - alembic run update query without specifying model to avoid later migrations clash

I am adding a field to my table using alembic. I am adding the field last_name, and filling it with data using do_some_processing function which loads data for the field from some other source. This is the table model, I added the field last_name…
dina
  • 4,039
  • 6
  • 39
  • 67
2
votes
1 answer

How can I extend every unique key constraint of all models with a common key across using Flask-SQLAlchemy and Flask-Migrate in Python?

Want to extend every unique key constraint of all models with a common key across. Have tried multiple things but doesn't seem to working when I do flask db init; flask db migrate -m "init"; flask db upgrade; But it works and…
2
votes
1 answer

Unicode not consistently working with Alembic

I have a migration that is running some custom code that depends on unicode characters. I am currently using SQLAlchemy 1.1.9 and Alembic 1.0.2. I can see my database and table have all the right settings: mysql> SELECT @@character_set_database,…
Charles L.
  • 5,795
  • 10
  • 40
  • 60
2
votes
1 answer

Alembic: alter column to JSON type

I have initial migration setup, but I want to change a column from sqlalchemy.Text to sqlalchemy.JSON I followed this article https://amercader.net/blog/beware-of-json-fields-in-sqlalchemy/ column_foo = Column(mutable_json_type(dbtype=JSONB,…
mehekek
  • 113
  • 9
2
votes
1 answer

Python 3.10.6 alembic postgresql password with special character

migrations/env.py: f = open("/etc/config.json", "r") json_config = json.load(f) config = context.config section = config.config_ini_section print(f"password: {json_config['DB_PASSWORD']}, host: {json_config['DB_HOST']}, db:…
Kok How Teh
  • 3,298
  • 6
  • 47
  • 85
2
votes
1 answer

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 unique revision identifier of each migration that…
Darragh Enright
  • 13,676
  • 7
  • 41
  • 48
2
votes
1 answer

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__ = ( PrimaryKeyConstraint("ID", name="PK_Table1"), ) ID =…
2
votes
1 answer

Alembic is giving me `RuntimeWarning: coroutine 'connect' was never awaited`

I 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 migrations. The error…
enchance
  • 29,075
  • 35
  • 87
  • 127
2
votes
1 answer

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.ini") command.history(alembic_cfg) And I should be…