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 Queries Are Your Friend

What is safe=True

Hello Why do I need to add safe = True in this code

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

1 Answer

Steven Parker
Steven Parker
231,248 Points

The expression "safe=True" is an optional keyword argument being passed to "create_tables". By setting it to True, the create table query will include an IF NOT EXISTS clause. This prevents an error from occurring if the table already exists in the database.

This information can be found using the link to Peewee query methods as provided in the "Teacher's Notes" section.