miguelgrinberg / Flask-Migrate

SQLAlchemy database migrations for Flask applications using Alembic
MIT License
2.36k stars 227 forks source link

Flask-Migrate does not create tables for dynamically added models #392

Closed dmitriypaulov closed 3 years ago

dmitriypaulov commented 3 years ago

Hello. Yesterday I started to develop own telegram bots mini-framework. So, the process was successful until I wanted to be able to create models dynamically via type() built-in. All created models do not exist globally, but are written to the list - object attribute. How can I explicitly tell Flask-Migrate that these models exist?

framework's main scipt: image

class, which creates models: image

In outer script I imported botify object from main script and call run() method. Flask-Migrate only creates migrations folder without any version.

miguelgrinberg commented 3 years ago

Flask-Migrate does not generate migrations, Alembic does. This is just a thin wrapper around Alembic to make it easier to use in Flask applications. Your question applies to Alembic, so this isn't the right place for it. I would think that as long as the models are properly registered with SQLAlchemy then Alembic should see them, so I suggest you make sure SQLAlchemy is okay with your dynamic models.