Why SQLalchemy create_all() can be reused? Why SQLalchemy create_all() can be reused? sqlite sqlite

Why SQLalchemy create_all() can be reused?


create_all indeed creates only tables that do not exist. It is not intended for migrations but to create the initial structure in an empty database.

You want alembic for migrations, possibly via Flask-Migrate


Besides that, having any database structure related code in the web-facing part of your Flask app is questionable. Usually you do such things in a command-line tool (via Flask-Script or click), e.g. python manage.py create_db.

I disagree with your opinion of "poorly implemented". It's rather implemented in a way that stops you from doing the wrong (and possibly dangerous) thing. Imagine you rename a column. A ""smart"" create_all would DROP the old column (it's gone after all) and create a new one - it's impossibly for any tool to know that you renamed it instead of removing and adding one.