from typing import List, Optional from enum import Enum import sqlalchemy as sa import sqlmodel class Status(str, Enum): active = "active" banned = "banned" status_enum = postgresql.ENUM("active", "banned", "c", name="status_enum") class User(sqlmodel.SQLModel, table=True): __tablename__ = "auth_user" id: int = sqlmodel.Field(primary_key=True) status: Status = sqlmodel.Field(status_enum) password: str
How to use Postgres Enums together with SQLModel?
Linux
No response
0.0.3
3.8.11
The answer:
Follow this enum template https://stackoverflow.com/a/6104825/4605629
And then use the sa_column= argument to specify the sqlalchemy column type.
I don't think this should be closed @gregsifr .
Your solution is a good workaround but the library should be able to handle it w/o manually setting a sa_column. Closing it reduces the visibility of the issue.
There seems to be a PR already up that tries to solve this -> #24
@gregsifr, could you please reopen the issue for the reasons stated above?
Apologies, I misunderstood and thought that since there is a PR for it there's no point to keep it open.
Merge pull request fastapi#31 from leynier/fork-18
Hey there! I think this was possibly solved in #165. That's available since SQLModel 0.0.7. Could you confirm?
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.
Activity
gregsifr commented on Aug 26, 2021
The answer:
Follow this enum template https://stackoverflow.com/a/6104825/4605629
And then use the sa_column= argument to specify the sqlalchemy column type.
andruli commented on Aug 27, 2021
I don't think this should be closed @gregsifr .
Your solution is a good workaround but the library should be able to handle it w/o manually setting a sa_column. Closing it reduces the visibility of the issue.
andruli commented on Aug 27, 2021
There seems to be a PR already up that tries to solve this -> #24
Bobronium commented on Sep 9, 2021
@gregsifr, could you please reopen the issue for the reasons stated above?
gregsifr commented on Sep 10, 2021
Apologies, I misunderstood and thought that since there is a PR for it there's no point to keep it open.
Merge pull request fastapi#31 from leynier/fork-18
tiangolo commented on Aug 30, 2022
Hey there! I think this was possibly solved in #165. That's available since SQLModel 0.0.7. Could you confirm?
github-actions commented on Sep 10, 2022
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.