If you have existing tables in your database, and they don't have a corresponding model in your code, Alembic (Flask-Migrate) only knows that there is a difference between your database and your code. It can't know (by default) that you meant to leave those tables untouched.
Pass an include_object
function to the environment to effect what database objects Alembic will generate commands for. The following example skips the listed table names, but allows everything else.
def include_object(object, name, type_, reflected, compare_to):
if type_ == 'table' and name in ('table', 'names', 'to', 'skip'):
return False
return True
# in env.py
context.configure(
# ...
include_object=include_object
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…