Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 679
user1992 Avatar asked Jan 20 '26 09:01

user1992


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!

like image 93
Shrey Sahgal Avatar answered Jan 22 '26 23:01

Shrey Sahgal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!