Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

manually changing alembic's HEAD position

An alembic migration that I ran recently errored out prematurely for system-related reasons. I had to cancel out and complete the migration manually. Now alembic is insisting that the migration has not been run.

I'd like to change the Alembic head position manually so that it believes that the migration has been completed. Is there a way to manually do this?

like image 977
jumbopap Avatar asked Jun 28 '17 14:06

jumbopap


People also ask

How do you change heads in alembic?

Show activity on this post. Delete (or move to another folder) the specific migration file (in migrations/versions folder). The head will automatically revert to the most recent remaining migration. Using stamp will set the db version value to the specified revision; not alter the head revision number.

What is alembic revision?

Alembic is the migration tool we use with SQLAlchemy. Alembic provides us with a simple way to create and drop tables, and add, remove, and alter columns. Fork and clone this repository and we'll walk through writing Alembic migrations together. To install Alembic, run pip install alembic in your terminal.

How does alembic migration work?

Usage of Alembic starts with creation of the Migration Environment. This is a directory of scripts that is specific to a particular application. The migration environment is created just once, and is then maintained along with the application's source code itself.

What is alembic Autogenerate?

Alembic can view the status of the database and compare against the table metadata in the application, generating the “obvious” migrations based on a comparison. This is achieved using the --autogenerate option to the alembic revision command, which places so-called candidate migrations into our new migrations file.


1 Answers

Use alembic stamp:

alembic stamp <revision>
like image 124
univerio Avatar answered Sep 21 '22 23:09

univerio