当前位置:网站首页>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()
看图:

边栏推荐
- Fe3O4/SiO2 Composite Magnetic Nanoparticles Aminated on SiO2-NH2/Fe3O4 Surface (Qiyue Reagent)
- install flask
- Error jinja2.exceptions.UndefinedError: 'form' is undefined
- Unity五子棋游戏设计 和简单AI实现(1)
- Unity 五子棋游戏设计和简单AI(2)
- Unity 五子棋游戏设计和简单AI(3)
- vs番茄助手的方便功能和便捷快捷键介绍
- 【Feel】Unity Feel插件中,Camera无法正确显示CameraShake
- Text String Length Sorting - Online Tool
- Cysteine/Galactose/Perylenediimide Functionalized Fe3O4 Fe3O4 Nanomaterials | Scientific Research Reagents
猜你喜欢

Unity backgammon game design and simple AI implementation (1)
![[MySQL]二、进程的关系、MySQL密码破解、建表和建库相关命令](/img/20/a0fb44e9360837146d0ed696c9e992.png)
[MySQL]二、进程的关系、MySQL密码破解、建表和建库相关命令

中英文说明书丨CalBioreagents 醛固酮单克隆抗体

网络学习总结

phpstudy install flarum forum

sql问题解答创建表的语句

C language implements sequential stack and chain queue

Adds, deletes, searches, and changes the leading doubly circular linked list (implemented in C language)

JMeter test - JMeter 】 【 upload multiple images/batch CSV file upload pictures interface parametric method

PDF不能打印和复制的问题如何解决?
随机推荐
为什么以太网无法接收大于1500字节的数据包?
Likou Brush Question 180
一道很简答但是没答对的SQL题
mmdetection源码解析--ResNet18
String.toLowerCase(Locale.ROOT)
phpstudy 安装 flarum论坛
CMake中INSTALL_RPATH与BUILD_RPATH问题
C语言实现顺序栈和链队列
golang xml 处理动态属性
22 high mid term paper topics forecast
crc计算
Unity五子棋游戏设计 和简单AI实现(1)
普罗米修斯原理及节点发布
Harbor Enterprise Mirror Warehouse Construction
S7-200SMART PLC Modbus TCP communication
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disab
Qt 学习(三) —— Qt 模块
mongo+ycsb性能测试及线程数分析
Teach you how to make the Tanabata meteor shower in C language - elegant and timeless (detailed tutorial)
Superparamagnetic iron [email protected]@cadmium sulfide nanocore-shell structure material|Fe3O4 magnetic nanop