Problems connecting to MySQL using Flask-sqlalchemy

Source: Internet
Author: User

From Flask_sqlalchemy import sqlalchemyimport mysqlimport Mysqldbapp = Flask (__name__) app.config[' Sqlalchemy_database _uri '] = ' mysql://root:[email protected]:3306/testbase?charset=utf8mb4 ' app.config[' Sqlalchemy_commit_on_teardown ' ] = Truedb = SQLAlchemy (APP) class User (db. Model):    __tablename__ = ' users ' #定义数据库中的表名    id = db. Column (db. Integer, Primary_key = True) #主键    username = db. Column (db. String (+), unique = True) #用户名, duplicate    password = db is not allowed. Column (db. String (nullable = False) #密码, not allowed for null if __name__ = = ' __main__ ':    app.run ()

Refer to the content on the Internet using Flask-sqlalchemy to connect to MySQL

The process is not smooth, encountered a variety of problems

1, 1049, "Unknown database"

SQLAlchemy cannot help you create a database, you must connect to an already established database.

Go to command line mysql-> CREATE DATABASE testbase

Build the database.

2, 1146, "Table ' performance_schema.session_variables ' doesn ' t exist"

Resolve after adding "import MySQLdb" and "Import MySQL". specifically to join which no test

Problems connecting to MySQL using Flask-sqlalchemy

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.