1

I need to upgrade a model (add some columns) in my Flask app and I try to use Flask-Migrate to do this.

Problem : No support for ALTER of constraints in SQLite.

Commands I used : db migrate > db upgrade

I read that there's probably something in the env.py file of migrations folder that needs to be changed but I'm a bit lost with that.

I don't want to drop/create all stuff..

I use Flask-SQLAlchemy to manage my database stuff.

Here is the code auto generated by Alembic for the migration :

from alembic import op
import sqlalchemy as sa

... # revisions identifiers

def upgrade():
    op.create_foreign_key(None, 'notes', 'user', ['owner_id'], ['id'])
    op.add_column('user', sa.Column('name', sa.String(length=50), ))
    op.add_column('user', sa.Column('website', sa.String(length=120), nullable=True))


def downgrade():
    op.drop_column('user', 'website')
    op.drop_column('user', 'name')
    op.drop_constraint(None, 'notes', type_='foreignkey')

Could you help me ?

dnmxm
  • 260
  • 1
  • 11
  • Can you post the full migration code (the ALTER statements) you want to run? – Milan Cermak Jun 07 '20 at 15:33
  • 1
    SQLite does not support changes to columns. Alembic has a "batch mode" feature, which copies the entire table into a new table to make these changes. While not a great solution, it does allow you to make changes to the schema. Search "Alembic batch mode" to find details about this. – Miguel Grinberg Jun 07 '20 at 17:29

0 Answers0