The classes that we have created are derived from the attribute of the Database object. It means that they are not ordinary classes, but entities. The entity instances are stored in the database, which is bound to the db variable. With Pony you can work with several databases at the same time, but each entity belongs to one specific database.

    Inside the entity Person we have created three attributes – name, age and cars. The name and age are mandatory attributes. In other words, these attributes cannot have the None value. The name is a string attribute, while age is numeric.

    The Car entity has three mandatory attributes: make and model are strings, and the owner attribute is the other side of the one-to-many relationship. Relationships in Pony are always defined by two attributes which represent both sides of a relationship.

    If we need to create a many-to-many relationship between two entities, we should declare two attributes at both ends. Pony creates the intermediate database table automatically.

    If you need to check an entity definition in the interactive mode, you can use the show() function. Pass the entity class or the entity instance to this function for printing out the definition:

    1. >>> show(Person)
    2. id = PrimaryKey(int, auto=True)
    3. age = Required(int)

    You may notice that the entity got one extra attribute named id. Why did that happen?

    When the primary key is created automatically, it always has the option auto set to . It means that the value for this attribute will be assigned automatically using the database’s incremental counter or a database sequence.