Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Yaxin Yuan
11,191 Points'MySQLDatabase' is not defined?
from peewee import *
db = MySQLDatabase('my_database')
class Student(Model):
username = CharField(max_length = 255, unique = True)
points = IntegerField(default=0)
class Meta:
database = db
if __name == '__main__':
db.connect()
db.create_tables([Student], safe = True)
For peewee tutorial, i did not use sqllite, instead, I used Mysql, which I already installed the workbench for "database foundation". But I got
name 'MySQLDatabase' is not defined... Is there anything that I was supposed to do before writing this script? Thank you!
2 Answers
Kenneth Love
Treehouse Guest TeacherI'm pretty sure but I should ask anyway: you're trying this on your own computer and not in Workspaces, correct?
Looking at the docs, either MySQLdb or pymysql has to be installed as well. You'd install either of these with pip.
I'll try it out myself and see what I can figure out.
EDIT:
I installed pymysql, created a database named 'diary', and changed from SqliteDatabase to MySQLDatabase and ran the script. Everything seemed to work, I was able to add and select a record and they all showed up when I queried the table directly.
Yaxin Yuan
11,191 PointsGot it, thanks!
Yaxin Yuan
11,191 PointsYaxin Yuan
11,191 PointsI managed to install pymysql, but that did not help though. For MySQLdb, I got "Could not find any downloads that satisfy the requirement..." when trying pip install.... FYI: I use a windows machine...