当前位置:网站首页>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()
看图:
边栏推荐
猜你喜欢
随机推荐
After the VB.net program is closed, the background is still connected to SQL
Magnetic Core-Shell Fe3O4 Particles Supported Gold Nanostars | Magnetic Fe3O4-POSS-COOH | Superparamagnetic Fe3O4-Polydopamine Core-Shell Nanoparticles
Web APIs BOM- 操作浏览器:本地存储
C language implements sequential stack and chain queue
A test engineer with an annual salary of 35W was laid off. Personal experience: advice that you have to listen to
关于如何查找NXP S32K1xx系列单片机的封装信息和引脚定义
运算放大器(OPA)超详细参数讲解-运放---以及8个型号的运算放大器分析对比
语句加锁分析
flask创建数据库失败未报错
SiO2 / KH550 modified ferroferric oxide nano magnetic particles | PDA package the ferromagnetic oxide nanoparticles (research)
2022-08-08: Given an array arr, it represents the height of the missiles that will appear in order from morning to night.When the cannon shoots missiles, once the cannon is set to shoot at a certain h
05 多线程与高并发 - ThreadPoolExecutor 源码解析
kubernetes security
Teach you how to make the Tanabata meteor shower in C language - elegant and timeless (detailed tutorial)
uniapp实现防抖搜索
Polyamide-amine (PAMAM) dendrimer-bismuth sulfide composite nanoparticles | bismuth sulfide modified Gd‑DTPA‑OA ligand | for scientific research
带头双向循环链表的增删查改(C语言实现)
ZIP压缩包文件删除密码的方法
Harbor Enterprise Mirror Warehouse Construction
深度学习-神经网络原理2