Skip to content

How to specify a different name for the db table that a SQLModel refers to?Β #159

@taranlu-houzz

Description

@taranlu-houzz

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 Optional

from sqlmodel import SQLModel, Field

# If the actual db table is called `assets`, for example, how can I keep the following model named `Product` but have it refer to the correct table?

class Product(SQLModel, table=True):

    id: Optional[int] = Field(None, primary_key=True)
    name: str

Description

  • I have an existing database with table names that are different than what I would like my model names to be.
  • The documentation here under the "SQL Table Names" section notes that there will be information on how to do this in the "Advanced Guide," but that section has not been worked on yet...

Operating System

Linux, macOS

Operating System Details

No response

SQLModel Version

0.0.4

Python Version

3.10.0

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions