Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Flask Framework Cookbook

You're reading from   Flask Framework Cookbook Over 80 proven recipes and techniques for Python web development with Flask

Arrow left icon
Product type Paperback
Published in Jul 2019
Publisher
ISBN-13 9781789951295
Length 302 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Shalabh Aggarwal Shalabh Aggarwal
Author Profile Icon Shalabh Aggarwal
Shalabh Aggarwal
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Flask Configurations FREE CHAPTER 2. Templating with Jinja2 3. Data Modeling in Flask 4. Working with Views 5. Webforms with WTForms 6. Authenticating in Flask 7. RESTful API Building 8. Admin Interface for Flask Apps 9. Internationalization and Localization 10. Debugging, Error Handling, and Testing 11. Deployment and Post-Deployment 12. Microservices and Containers 13. Other Tips and Tricks 14. Other Books You May Enjoy

Migrating databases using Alembic and Flask-Migrate

Now, let's say we want to update our models to have a new field called company in the Product model. One way is to drop the database and then create a new one using db.drop_all() and db.create_all(). However, this approach cannot be followed for applications in production or even in staging. We would want to migrate our database to match the newly updated model with all the data intact.

For this, we have Alembic, which is a Python-based tool to manage database migrations and uses SQLAlchemy as the underlying engine. Alembic provides automatic migrations to a great extent with some limitations (of course, we cannot expect any tool to be seamless). To act as the icing on the cake, we have a Flask extension called Flask-Migrate, which eases the process of migrations even more. In this recipe, we will cover the basics of database...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime