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 trialMarcin Mączewski
4,476 Pointspeewee.OperationalError: table student has no column named points
I keep getting "peewee.OperationalError: table student has no column named points" error, any ideas why? I looked through and through and couldn't figure it out.
from peewee import *
db = SqliteDatabase('students.db')
class Student(Model):
username = CharField(max_length=255, unique=True)
points = IntegerField(default=0)
class Meta:
database = db
students = [
{'username': 'kennethlove',
'points': 4888},
{'username': 'chalkers',
'points': 11912},
{'username': 'joykesten2',
'points': 7363},
{'username': 'craigsdennis',
'points': 4079},
{'username': 'davefarland',
'points': 14717},
]
def add_students():
for student in students:
try:
Student.create(username=student['username'],
points=student['points'])
except IntegrityError:
student_record = Student.get(username=student['username'])
student_record.points = student['points']
student_record.save()
def top_student():
student = Student.select().order_by(Student.points.desc()).get()
return student
if __name__ == '__main__':
db.connect()
db.create_tables([Student], safe=True)
add_students()
print("Our top student right now is: {0.username}.".format(top_student()))
2 Answers
Kris Budhram
6,080 PointsI copied your code and could not reproduce the error.
The error you get indicate a problem with the students.db file. Have you tried removing it and trying again?
Elizabeth Keleshian
1,844 PointsI also have this issue. Don't know what's wrong. Here's my code.
from peewee import *
db = SqliteDatabase('students.db')
class Student(Model): username = CharField(max_length=255, unique=True) #field that holds characters points = IntegerField(default=0)
class Meta: #isn't a meta class
database = db
students = [ {'username': 'liz', 'points':288}, {'username': 'chalkers', 'points':1912}, {'username': 'joy', 'points':2348}, {'username': 'peter', 'points':258}, {'username': 'davidcraig', 'points':25256} ]
def add_students(): for student in students: try: Student.create(username=student['username'], points=student['points']) except IntegrityError: student_record = Student.get(username=student['username']) student_record.points = student['points'] student_record.save()
if name == 'main': db.connect() db.create_tables([Student], safe=True) #Peewee won't break add_students()