Altering an Enum field using Alembic

I decided to try to follow the postgres approach as directly as possible and came up with the following migration. from alembic import op import sqlalchemy as sa old_options = (‘nonexistent_executable’, ‘signal’, ‘success’, ‘timed_out’) new_options = sorted(old_options + (‘output_limit_exceeded’,)) old_type = sa.Enum(*old_options, name=”status”) new_type = sa.Enum(*new_options, name=”status”) tmp_type = sa.Enum(*new_options, name=”_status”) tcr = sa.sql.table(‘testcaseresult’, sa.Column(‘status’, … Read more

Alembic: IntegrityError: “column contains null values” when adding non-nullable column

It is because your existing data have no value on that new column, i.e. null. Thus causing said error. When adding a non-nullable column, you must decide what value to give to already-existing data Alright, existing data should just have “lorem ipsum” for this new column then. But how do I do it? I can’t … Read more

Using Alembic API from inside application code

Here’s what I’ve learned after hooking up my software to alembic: Is there a way to call alembic from inside my Python code? Yes. As of this writing the main entry point for alembic is alembic.config.main, so you can import it and call it yourself, for example: import alembic.config alembicArgs = [ ‘–raiseerr’, ‘upgrade’, ‘head’, … Read more

Undo last Alembic migration

Assuming that you only want to go back one revision, use alembic downgrade with a relative migration identifier of -1: alembic downgrade -1 This will run the downgrade() method of your latest revision and update the alembic_version table to indicate the revision you’re now at. If you need to go back multiple migrations, run alembic … Read more

Target database is not up to date

After creating a migration, either manually or as –autogenerate, you must apply it with alembic upgrade head. If you used db.create_all() from a shell, you can use alembic stamp head to indicate that the current state of the database represents the application of all migrations.

How do I execute inserts and updates in an Alembic upgrade script?

What you are asking for is a data migration, as opposed to the schema migration that is most prevalent in the Alembic docs. This answer assumes you are using declarative (as opposed to class-Mapper-Table or core) to define your models. It should be relatively straightforward to adapt this to the other forms. Note that Alembic … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)