Flask's Migrate

Source: Internet
Author: User

51777190

This method can:

Https://www.cnblogs.com/caicairui/p/7821586.html

ImportOS fromAppImportCreate_app, DB fromFlask_scriptImportManager, Shell fromFlask_migrateImportMigrate, Migratecommand#app = Create_app (os.getenv (' flask_config ') or ' default ')App =Create_app () Manager=Manager (APP) Migrate=Migrate (app, db) Manager.add_command ('DB', Migratecommand)if __name__=='__main__': Manager.run ()

First time use:

    1. Initialize: (venv) python manage.py db init This command creates the Migrations folder under the project, where all migration scripts are stored.
    2. Create first version: (venv) $ python manage.py db migrate-m "Initial migration" check Migrations\versions, a new version is created. PY, check the form and field inside
    3. Running the upgrade (venv) $ python manage.py DB upgradewill update the database files used by the project to new tables, fields, while preserving the data

Suffix Update:

    1. Update a table's fields (models.py)
    2. Run again db migrate-m, equivalent to commit update to/migrate directory
    3. DB upgrade-database is updated

Initialization
(venv) $ Python manage.py db init
Create a migration script
(venv) $ Python manage.py db migrate
Update Database
(venv) $ python manage.py db upgrade

Flask's 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.