Python-flask-flask-sqlalchemy and Flask-migrate combined for data migration

Source: Internet
Author: User

Steps to use:

1. Introduction of Flask-sqlalchemyfromimport= SQLAlchemy ()  
2. Register flask-SQLAlchemy    db.init_app (APP)
3. Import the tables in models  fromimport *
4. Write class inherits Db. Model  class  Users (db. Model):      __tablename__'users'    = Column (Integer, primary _key=true)
5th step:    Installing PIP3 install Flask-migrate
5.1 Import
Import Migrate, Migratecommand
Import Create_app, DB
   5.2 Creating the Migrate sample
Migrate = Migrate (App, DB)
   5.3 Create DB command
Manager.add_command (' db ', Migratecommand)
6th step
Execute command: initial: Python manage.py db init python manage.py db migrate #生成数据结构 python manage.py db upgrade #在数据库中创建表信息
7th step:
When executing SQL later: mode one: = db.session.query (models. User.id,models. User.Name). All ()
db.session.remove () mode two: = models. Users.query.all ()

Python-flask-flask-sqlalchemy and Flask-migrate combined for data migration

Related Article

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.