Skip to content
Discussion options

You must be logged in to vote

In current version (0.0.24) it already works this way:

from enum import Enum
from sqlmodel import SQLModel, Field, create_engine

class Role(str, Enum):
    ADMIN = "admin"
    EDITOR = "editor"

class User(SQLModel, table=True):
    id: int | None = Field(default=None, primary_key=True)
    username: str = Field(max_length=25)
    role: Role

engine = create_engine("sqlite:///", echo=True)
SQLModel.metadata.create_all(engine)

Output:

CREATE TABLE user (
        id INTEGER NOT NULL, 
        username VARCHAR(25) NOT NULL, 
        role VARCHAR(6) NOT NULL, 
        PRIMARY KEY (id)
)

Replies: 5 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@TGoddessana
Comment options

@fcaspani01
Comment options

@TGoddessana
Comment options

@DarylDohner20
Comment options

@HeiziND
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
8 participants