当前位置:网站首页>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()
看图:
边栏推荐
- 按图搜索1688商品接口(item_search_img-按图搜索1688商品(拍立淘接口)代码对接教程
- [MySQL] Second, the relationship between processes, MySQL password cracking, table building and database building related commands
- qt send mail program
- kubernetes security
- Service
- 缓存技术使用
- untiy countdown
- zip压缩包密码解密
- MYSQLg advanced ------ batch insert millions of data
- db.sqlite3没有“as Data Source“解决方法
猜你喜欢
[GO]、数组与切片
The solution that does not work and does not take effect after VScode installs ESlint
install flask
mongo+ycsb性能测试及线程数分析
Unity C# 委托——事件,Action,Func的作用和区别
IQ Products CMV Brite Turbo试剂盒的原理
Polyamide-amine (PAMAM) dendrimer-bismuth sulfide composite nanoparticles | bismuth sulfide modified Gd‑DTPA‑OA ligand | for scientific research
中英文说明书丨TRC 交替醇(Catalogue NumberA575760)
Unity五子棋游戏设计 和简单AI实现(1)
Harbor Enterprise Mirror Warehouse Construction
随机推荐
Cysteine/Galactose/Perylenediimide Functionalized Fe3O4 Fe3O4 Nanomaterials | Scientific Research Reagents
阿里巴巴官方技术号
Use of PlantUML plugin in idea
Xilinx Zynq ZynqMP DNA
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
MongDb的查询方式
使用百度EasyDL实现智能垃圾箱
[R language] Normalize and organize files into folders of various file types
关于如何查找NXP S32K1xx系列单片机的封装信息和引脚定义
Fe3O4/SiO2 Composite Magnetic Nanoparticles Aminated on SiO2-NH2/Fe3O4 Surface (Qiyue Reagent)
Excel受保护的工作表怎么操作?
jdepend
代码目录结构
Bismuth sulfide nanorods with CT imaging function | Bismuth sulfide-zinc protoporphyrin composites (PAMAM/Bi2S3 composite nanoparticles)
声母-字母查询工具-词语缩写查询在线工具
Error jinja2.exceptions.UndefinedError: 'form' is undefined
【R语言】对文件进行归一化整理到各文件类型文件夹
Go lang1.18入门精炼教程——第一章:环境搭建
VS2019常用快捷键
一道很简答但是没答对的SQL题