1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Databases in Python

Exercise

Constraints and data defaults

You're now going to practice creating a table with some constraints! Often, you'll need to make sure that a column is unique, nullable, a positive value, or related to a column in another table. This is where constraints come in.

As Jason showed you in the video, in addition to constraints, you can also set a default value for the column if no data is passed to it via the default keyword on the column.

Instructions

100 XP
  • Table, Column, String, Integer, Float, Boolean are already imported from sqlalchemy.
  • Build a new table called data with a unique name (String), count (Integer) defaulted to 1, amount (Float), and valid (Boolean) defaulted to False.
  • Hit 'Submit Answer' to create the table in the database and to print the table details for data.