How to add new table in existing database of flask app using sqlalchemy?

Viewed 1660

I want to add a new table in existing database without affecting existing tables and its datas. After adding new model class into models.py, what are steps needs to follow to add new table?

1 Answers

Once you've added the new model in your models.py, you just need to run db.create_all(). You can add this in your code somewhere (probably directly) after you initialize your app/database. Be sure to include with app.app_context() if you aren't calling create_all in a view. Hope this helps!

Related