3

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?

2

1 Answer 1

1

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!

Sign up to request clarification or add additional context in comments.

2 Comments

Will using db.create_all() reset the data in the existing tables?
I think create_all() first checks for the existence of the tables in the model and will only create tables that don't digging through the docs I found this example: employees.create(engine, checkfirst=True) where checkfirst is True by default

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.