Skip to content
Discussion options

You must be logged in to vote

You can set it manually by

class MyTable(SQLModel, table=True):
    __tablename__ = "my_table"
    ...

Or specify function that will be used to generate name (useful if you specify it in base class):

from typing import Optional

from pydantic.alias_generators import to_snake
from sqlalchemy.orm import declared_attr
from sqlmodel import Field, SQLModel, create_engine

class SQLModelBase(SQLModel):
    @declared_attr.directive  # type: ignore[misc]
    @classmethod
    def __tablename__(cls) -> str:
        return to_snake(cls.__name__)

class MyTable(SQLModelBase, table=True):
    ...

Replies: 1 comment

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