Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python peewee.ImproperlyConfigured: MySQL driver not installed

I tried to make a MySQL connection with peewee and followed the tutorial from their website: peewee quickstart

So my code is the following:

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()

(My Database is from xampp)

But when i execute this code I get this error message:

peewee.ImproperlyConfigured: MySQL driver not installed!

I tried to fix this by installing this MySQL Driver. But this changed absolutely nothing. Due to me beeing new to python I have no idea what I can do to fix this, if i'm just missing a import or if I have to install a library with pip?

like image 626
Tamino W. Avatar asked Jul 13 '20 12:07

Tamino W.


2 Answers

Install a MySQL driver:

pip install pymysql
like image 155
tread Avatar answered Sep 18 '22 22:09

tread


The docs are clear, as is the error message: http://docs.peewee-orm.com/en/latest/peewee/database.html#using-mysql

Install pymysql or mysqldb.

To use the non-standard mysql-connector driver, you need to import the playhouse.mysql_ext module and use the MySQLConnectorDatabase implementation:

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

like image 37
coleifer Avatar answered Sep 18 '22 22:09

coleifer