Unable to create primary key

19 views
Skip to first unread message

David Robinson

unread,
Jun 10, 2021, 8:51:25 PM6/10/21
to peewee-orm
I am attempting implement a simple primary key id column from the example in the quick start and seem to be having difficult. The following code does results in a IntegrityError: NOT NULL constraint failed: person.name. Is there something I am missing?

from peewee import *

db = SqliteDatabase('people.db')

class Person(Model):
    id = IntegerField(primary_key=True)
    name = CharField()
    birthday = DateField()

    class Meta:
        database = db # This model uses the "people.db" database.
        
db.connect()
db.create_tables([Person])

from datetime import date
uncle_bob = Person(id=1, name='Bob', birthday=date(1960, 1, 15))
uncle_bob.create()


David Robinson

unread,
Jun 11, 2021, 9:08:47 AM6/11/21
to peewee-orm
Quick update. After enabling logging I see the following queries:

('CREATE TABLE IF NOT EXISTS "person" ("id" INTEGER NOT NULL PRIMARY KEY, "name" VARCHAR(255) NOT NULL, "birthday" DATE NOT NULL)', [])
('INSERT INTO "person" DEFAULT VALUES', [])

It looks like the table is being properly created but the values aren't being populated in the query.
Reply all
Reply to author
Forward
0 new messages