FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

How to deal with Postgres Enum columns? · Issue #31 · fastapi/sqlmodel · GitHub

Repository navigation

How to deal with Postgres Enum columns?  #31

Closed

Description

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 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

Description

How to use Postgres Enums together with SQLModel?

Operating System

Linux

Operating System Details

No response

SQLModel Version

0.0.3

Python Version

3.8.11

Additional Context

No response

Activity

  1. changed the title [-]How to deal with Postgres Enums? [/-] [+]How to deal with Postgres Enum columns? [/+] on Aug 26, 2021
  2. gregsifr commented on Aug 26, 2021

    Author

    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.

  3. 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.

  4. andruli commented on Aug 27, 2021

    There seems to be a PR already up that tries to solve this -> #24

  5. Bobronium commented on Sep 9, 2021

    Contributor

    @gregsifr, could you please reopen the issue for the reasons stated above?

  6. gregsifr commented on Sep 10, 2021

    Author

    Apologies, I misunderstood and thought that since there is a PR for it there's no point to keep it open.

  7. added a commit that references this issue on Jun 24, 2022
  8. tiangolo commented on Aug 30, 2022

    Member

    Hey there! I think this was possibly solved in #165. That's available since SQLModel 0.0.7. Could you confirm?

  9. github-actions commented on Sep 10, 2022

    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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


      Back | FazBrowse Home | New Git URL