peewee.IntegrityError:NOT NULL 约束失败:user.id

问题描述 投票:0回答:0

''' 从 peewee 导入 *

forum_db = SqliteDatabase("forum.db")

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

class User(BaseModel):
    name = CharField(unique = True)
    id = IntegerField()

class Post(BaseModel):
    id = IntegerField()
    message = TextField()
    user_id = ForeignKeyField(User, backref = "id")

class Thread(BaseModel):
    id = IntegerField()
    title = CharField()
    user_id = ForeignKeyField(User, backref = "id")
    posts = ForeignKeyField(Post)

if __name__ == "__main__":
    forum_db.connect()
    forum_db.create_tables([User, Post, Thread])

    User.create(id = 1, name = "Cameron")

'''

我正在为我正在制作的简单论坛 API 创建一个数据库。尽管当我尝试创建用户时,它给了我标题中的错误。我输入了 ''' id = 1 ''',所以我不确定如何解决这个问题。

python database sqlite peewee
© www.soinside.com 2019 - 2024. All rights reserved.