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

Python Using Databases in Python Meet Peewee Modeling

Why is the name of the table student and not Student?

In the video, we create the following :

  • students.db, the SQLite database
  • Student, our model (capital S) Then we run the following : db.create_tables([Student], safe=True) (capital S again)

And the name of the table, as we see it in SQLite is student (without the capital S). I don't see where we create anything called student (without the capital S) . Is it just because names for SQL tables don't use capital letters?

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Buried in the peewee code for ModeOptions.__init__() is the line self.model_class = cls.__name__.lower(). This lowercases all Model names before the tables are created.

This brings up the interesting case of what happens when you have two Models with same name but different case such as User and UseR. These are distinct within Python. Now when peewee creates the tables for these using:

    DATABASE.create_tables([UseR, User, Post, Relationship], safe=True)

Whichever of the two Models is listed first will be created, the second will not be created as the table appears to have been created.

There is a Meta parameter you can set to force the table case (but it's not used in normal practice):

class ModelOne(Model):
    class Meta:
         database = db
         db_table = 'modelOne'
Konrad Pilch
Konrad Pilch
2,435 Points

Im not sure, but i heared to to keep the letters lowercase , id thats database, saving a index.html file or whatever. If you have two words you do it like that student_mod not like studentMod . At least thats what i do , but yet, maybe in python its different.