使用flask-sqlalchemy串連mysql遇到的問題

來源:互聯網
上載者:User

標籤:ring   問題   python   base   tab   conf   name   mod   rdo   

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(16), unique = True) #使用者名稱,不允許重複    password = db.Column(db.String(20), nullable = False) #密碼,不允許為空白if __name__ == ‘__main__‘:    app.run() 

參照網上的內容使用flask-sqlalchemy串連Mysql

 

 過程並不順利,遇到了各種問題

1、1049, "Unknown database" 

  sqlalchemy不能幫你建立資料庫,必須串連到已經建立的資料庫。

  進入命令列 mysql-> CREATE DATABASE testbase

  建立資料庫。

2、1146, "Table ‘performance_schema.session_variables‘ doesn‘t exist"

  加入“import MySQLdb”和“import mysql”後解決。具體是加入哪個沒有測試

 

使用flask-sqlalchemy串連mysql遇到的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.