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
203,728 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.