Connect to MySQL database and create user model

Source: Internet
Author: User
Tags mysql create mysql create database

  1. Installing and configuring the Python3.6+flask+mysql database
    1. Download and install MySQL database
    2. Download and install Mysql-python middleware
    3. Pip Install Flask-sqlalchemy (Python's ORM Framework SQLAlchemy)
  2. MySQL CREATE database

  3. Database configuration Information config.py
    ' mysql+pymysql://root: @localhost: 3306/mis_db?charset=utf8 '  = False

  4. establish MySQL and app connections
     from  flask import   flask,render_template  from  flask_sqlalchemy import   SQLAlchemy  import   Configapp  = Flask (__name__ ) #   Initializes a flask object that needs to pass a parameter __name__  app.config.from_object ( Config) db  =sqlalchemy (APP) Db.create_all ()  

     

  5. Create a user model
    #/Create the User model class "user" (db). Model):    __tablename__ = ' user '    id=db. Column (db. integer,primare_key=taberror,autoincrement=True)    username=db. Column (db. String (a), nullable=False)    password=db. Colum (db. String (), nullable=False)    

Connect to MySQL database and create user model

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.