sqliteflaskflask-migrate

sqlite flask db migrate issues, alter, and constraints


I have been using flask db migrate, but in between some columns are already manually changed in database thus I don't need those specific migration files. Unfortunately everytime I run flask db migrate command, it still creates downgrade and upgrade commands for those columns that I am forced to delete manually. How do I fix this issue, my database currently is in correct state, how do I enforce that so flask db migrate resets its understanding of current state

edit 1 I am using sqlite, The issue started with alter table where sqlite not working with that, current solution I tried is this Migrate(app, db, compare_type=True, render_as_batch=True)

edit 2 also constraint are becoming a problem with sqlite. It is not giving a name to constraints so I am having to do myself manually


Solution

  • solved this with using convention dict

    convention = {
    "ix": "ix_%(column_0_label)s",
    "uq": "uq_%(table_name)s_%(column_0_name)s",
    "ck": "ck_%(table_name)s_%(constraint_name)s",
    "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
    "pk": "pk_%(table_name)s"
    }
    
    
    db = SQLAlchemy(metadata=MetaData(naming_convention=convention))
    

    and

    migrate = Migrate(app, db, compare_type=True, render_as_batch=True)