Skip to content

How to make enum column to work with SQLModel? #96

Closed
@haja-k

Description

@haja-k

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the SQLModel documentation, with the integrated search.
  • I already searched in Google "How to X in SQLModel" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to SQLModel but to Pydantic.
  • I already checked if it is not related to SQLModel but to SQLAlchemy.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from sqlmodel import SQLModel, Field, JSON, Enum, Column
from typing import Optional
from pydantic import BaseModel
from datetime import datetime

class TrainingStatus(str, enum.Enum):
    scheduled_for_training = "scheduled_for_training"
    training = "training"
    trained = "trained"

class model_profile(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    training_status: Column(Enum(TrainingStatus))
    model_version: str

Description

I am trying to create an enum column and use the value in the database. But I am getting this error:

RuntimeError: error checking inheritance of Column(None, Enum('scheduled_for_training', 'training', 'trained', name='trainingstatus'), table=None) (type: Column)

Does anyone knows how to help me? I tried

training_status: Column('value', Enum(TrainingStatus))

but it doesn't seem to work as I don't understand where the 'value' should be coming from 😓 I would really appreciate any input

Operating System

macOS

Operating System Details

No response

SQLModel Version

0.0.4

Python Version

3.7.9

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    answeredquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions