DEV Community

Free Python Code
Free Python Code

Posted on

How to Setting Default UUID for User Model in Peewee

hi 🙂🖐

How to Setting Default UUID for User Model in Peewee

from peewee import SqliteDatabase, Model, UUIDField, CharField, IntegerField
from uuid import uuid4


db = SqliteDatabase('mydb.db')

class User(Model):
    userId = UUIDField(default= uuid4)
    name = CharField(max_length = 20)
    age = IntegerField()
    password = CharField(max_length = 100)

    class Meta:
        database = db

db.connect()

db.create_tables([User])
db.commit()

user = User.create(
    name = 'amr',
    age = 20,
    password = '123'
)


user.save()
Enter fullscreen mode Exit fullscreen mode

Top comments (0)