之前Flask的SQLAlchemy中,使用的是sqlite
虽然方便,但是貌似据说不支持重命名Column
另外,为了长远考虑,还是mysql支持功能更多,有更多的第三方工具查看数据
所以打算去改为mysql
目前的配置是:
/Users/crifan/dev/dev_root/daryun/SIPEvents/sourcecode/sipevents/instance/config.py
/Users/crifan/dev/dev_root/daryun/SIPEvents/sourcecode/sipevents/sipevents/__init__.py
from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_images import Images from flask_login import LoginManager from flask_rq2 import RQ import logging from logging.handlers import RotatingFileHandler app = Flask(__name__, instance_relative_config=True) app.config.from_object(‘config’) # load config.py app.config.from_pyfile(‘config.py’) app.debug = app.config["FLASK_DEBUG"] db = SQLAlchemy(app) |
SQLAlchemy mysql
MySQL — SQLAlchemy 1.1 Documentation
python使用sqlalchemy连接mysql数据库 – 简书
配置 — Flask-SQLAlchemy 0.16 documentation
[zz]sqlalchemy连接mysql数据库初探 – zaleilynn – 博客园
Flask-SQLAlchemy配置MySQL及其相关操作 – 前行 – 博客频道 – CSDN.NET
-》[已解决]SQLAlchemy中的SQLALCHEMY_COMMIT_ON_TEARDOWN
另外需要:
➜ ~ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 572 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement. mysql> show databases; +——————–+ | Database | +——————–+ | information_schema | | gogs | | keyoutong | | mysql | | sipevents | | test | +——————–+ 6 rows in set (0.00 sec) mysql> create database runningfast_dev; Query OK, 1 row affected (0.00 sec) mysql> show databases; +——————–+ | Database | +——————–+ | information_schema | | gogs | | keyoutong | | mysql | | runningfast_dev | | sipevents | | test | +——————–+ 7 rows in set (0.00 sec) mysql> quit Bye |
# mysql://username:password@hostname/database SQLALCHEMY_DATABASE_URI = ‘mysql://roor:Jiandao123@localhost/sipevents’ |
结果又出错:
[已解决]SQLAlchemy中初始化mysql出错:ImportError: No module named MySQLdb
结果又出错:
然后再去测试测试运行Flask程序,看看是否正常。
结果,活动列表的标题等内容,显示就不对了,全是乱码:
另外:
点击创建活动,也没法输入文字标题了:
所以,感觉是问题很多啊。。。
算了,暂时还原回去,暂时还是用sqlite吧。
转载请注明:在路上 » [未解决]SQLAlchemy中把sqlite换成mysql