Skip to content

Creating column with an alias name #93

@gideonmandu

Description

@gideonmandu

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 Field, SQLModel


class CommonCrawler(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    domain: str
    country: Optional[str] = Field(default=None)
    whois: Optional[str] = Field(default=None)
    schemas: Optional[str] = Field(
        alias="schema", default=None, title="schema"
    )
    phone_number: Optional[str] = Field(default=None)
    city: Optional[str] = Field(default=None)

    class Config:
        title = 'common_crawler'

    def __repr__(self):
        return f"Domain(id={self.id!r}, domain={self.domain!r}, country={self.country!r})"

Description

I Tried creating a Table with schema as one of the columns but got an error NameError: Field name "schema" shadows a BaseModel attribute; use a different field name with "alias='schema'".
Error message adviced I use an alias and a diffrent column name.
I changed the name to schemas but its alias is not being applied on table creation.
I am using sqlite database for this specific use case.

Operating System

Linux

Operating System Details

Parrot security linux distro

SQLModel Version

0.0.4

Python Version

3.9.2

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