Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 :

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()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading