Python peewee.ImproperlyConfigured:未安装MySQL驱动程序

塔米诺·W。

我试图与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驱动程序!

我试图通过安装MySQL驱动程序来解决此问题但这绝对没有改变。由于我是python的新手,所以我不知道该如何解决此问题,如果我只是缺少导入文件,或者必须使用pip安装库?

鞘翅目

文档是清晰的,错误消息也是如此:http : //docs.peewee-orm.com/en/latest/peewee/database.html#using-mysql

安装pymysql或mysqldb。

要使用非标准的mysql-connector驱动程序,您需要导入playhouse.mysql_ext模块并使用MySQLConnectorDatabase实现:

http://docs.peewee-orm.com/zh-CN/latest/peewee/playhouse.html#mysql-ext

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章