我尝试与 peewee 建立 MySQL 连接,并按照他们网站上的教程进行操作:
peewee quickstart
所以我的代码如下:
from peewee import *
db = MySQLDatabase(
host='127.0.0.1',
user='root',
password='',
database='db_test'
)
class Person(Model):
name = CharField()
birthday = DateField()
class Meta:
database = db
class Pet(Model):
owner = ForeignKeyField(Person, backref='pets')
name = CharField()
animal_type = CharField()
class Meta:
database = db
db.connect()
db.create_tables([Person, Pet])
db.close()
(我的数据库来自 xampp)但是当我执行此代码时,我收到此错误消息:
peewee.ImproperlyConfigured: MySQL driver not installed!
我试图通过安装来解决这个问题
this
MySQL 驱动程序。但这完全没有改变。由于我是 python 的新手,我不知道我能做些什么来解决这个问题,如果我只是缺少一个导入或者我是否必须使用 pip 安装一个库?
最佳答案
安装 MySQL 驱动程序:
pip install pymysql
关于Python peewee.ImproperlyConfigured : MySQL driver not installed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62875416/