Manage database upgrades with Flask-migrate

Source: Internet
Author: User

When we upgrade the system, we often encounter the need to update the server-side data structure, and so on, the way is by hand-written alter SQL script processing, often found missing, resulting in the program published to the server will not work properly.

Now we can use the Flask-migrate plugin to solve it, flask-migrate plug-in is based on alembic,alembic is a data migration tool developed by the famous SQLAlchemy author.

Here's how:

1. Installing the Flask-migrate Plugin

Install Flask-migrate

2. Modify the code in the Flask app section to add migrate-related command

db = SQLAlchemy (APP) migrate = migrate (app, db) Manager = Manager (APP) Manager.add_command ('db', Migratecommand)     

3. Initialization

$ Python app.py db init

4. Data migration, automatically create migration code

$ Python app.py db migrate

5. Updating the database

$ Python app.py db upgrade

If there is a model change in the back, you only need to repeat the 4th and 5 steps in the development environment.

In the server side only need to perform a 5th step to achieve the database migration.

Manage database upgrades with Flask-migrate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.