'Peewee is creating the table with just the ID no other fields/columns are created

I'm trying to use peewee for the first time, I need to create the table associated with a single model called Applicant. The problem is that the table is being created just with ID field and nothing else

Pewee recomends having a base model class:

from peewee import *

db = SqliteDatabase('applicants.db')


class BaseModel(Model):
    class Meta:
        database = db

This is how my Applicant class is defined

class Applicant(BaseModel):
    email: CharField(max_length=200, unique=True)
    process_status: IntegerField(index=True)
    fullName: CharField(max_length=200)
    slackId: CharField(max_length=30)
    last_sent_time: DateTimeField()
    last_recieved_time: DateTimeField()

And this is how I'm trying to create the table


# Start your app
if __name__ == "__main__":
    conn = db.connect()
    db.create_tables([Applicant])


Solution 1:[1]

You've used type hinting syntax instead of initialization to define your model fields. It's an easy mistake to make here as you're probably thinking about the database types of each field, but you actually need to initialize the class variables with an instantiated "type object" representing each db column.

Just change : to =:

class Applicant(BaseModel):
    email = CharField(max_length=200, unique=True)
    process_status = IntegerField(index=True)
    fullName = CharField(max_length=200)
    slackId = CharField(max_length=30)
    last_sent_time = DateTimeField()
    last_recieved_time = DateTimeField()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Woodford