当前位置:网站首页>Flask failed to create database without error
Flask failed to create database without error
2022-08-09 06:28:00 【Koala Rice Bowl】
The code that the teacher gave us to create a database:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app=Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI']='mysql://root:[email protected]:3306/text'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS']=False
app.config['SQLALCHEMY_ECHO'] = True
db=SQLAlchemy(app)
class Role(db.Model):
__tablename__='roles'
id=db.Column(db.Integer,primary_key=True)
name=db.Column(db.String(16),unique=True)
class User(db.Model):
__tablename__='users'
id=db.Column(db.Integer,primary_key=True)
name=db.Column(db.String(16),unique=True)
role_id=db.Column(db.Integer,db.ForeignKey('roles.id'))
@app.route('/',methods=['post','get'])
def index():
return 'hello'
# 删除表
db.drop_all()
# 创建表
db.create_all()
if __name__=='__main__':
app.run(debug=True)
This above code maypython2.xRunning is correct but correct with what I installedpython环境是3.8It will run unsuccessfully but it will not report an error in the console
这是因为MySQLdb 只适用于python2.x,发现pip装不上.它在python3的替代品是: import pymysql
Add the following code to the import package
import pymysql
pymysql.install_as_MySQLdb()
看图:
边栏推荐
- 使用百度EasyDL实现智能垃圾箱
- 思维方法 解决问题的能力
- Excel受保护的工作表怎么操作?
- String.toLowerCase(Locale.ROOT)
- Unity 五子棋游戏设计和简单AI(3)
- flask创建数据库失败未报错
- BeautifulSoup4的介绍与使用
- Ferric oxide/bismuth sulfide nanocomposites ([email protected]@BSABiS nanoparticles) | dendrimer-stabilized bismuth sulfide nanop
- [HNOI2002]营业额统计
- Initials-Letter Query Tool-Word Abbreviation Query Online Tool
猜你喜欢
Fe3O4/SiO2 Composite Magnetic Nanoparticles Aminated on SiO2-NH2/Fe3O4 Surface (Qiyue Reagent)
线程的6种状态
Introduction to AIOT
Introduction of convenient functions and convenient shortcut keys of vs tomato assistant
Teach you how to make the Tanabata meteor shower in C language - elegant and timeless (detailed tutorial)
安装flask
Invalid argument(s) appears when redis runs lua script
网络学习总结
[email protected]@cadmium sulfide nanocore-shell structure material|Fe3O4 magnetic nanop"/>
Superparamagnetic iron [email protected]@cadmium sulfide nanocore-shell structure material|Fe3O4 magnetic nanop
static静态关键字和继承
随机推荐
tidb crash test
电学知识的疑问
IQ Products巨细胞病毒CMV感染检测试剂盒的特征和应用
思维方法 解决问题的能力
常用Oracle命令
线程的6种状态
flask创建数据库失败未报错
Xilinx Zynq ZynqMP DNA
普罗米修斯原理及节点发布
kubernetes security
单例模式
治疗消化性溃疡—Toronto Research Chemicals 甘氨酸铝
直接用的zip包 缺少很多依赖,pip没有,感觉用anaconda create一个环境会方便点
Web APIs BOM- 操作浏览器:本地存储
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disab
ZIP压缩包文件删除密码的方法
How to find package information and pin definitions for NXP S32K1xx series microcontrollers
Kubernetes apparmor profile
为什么以太网无法接收大于1500字节的数据包?
Unity 五子棋游戏设计和简单AI(3)