Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing primary_key is not supported when also passing a sa_column #150

Open
felixjichao opened this issue Dec 15, 2023 · 1 comment
Open

Comments

@felixjichao
Copy link

Run code from
fastapi-amis-admin-demo

class Category(SQLModel, table=True):
    id: int = Field(default=None, primary_key=True, nullable=False)
    name: str = Field(title="CategoryName", sa_column=Column(String(100), unique=True, index=True, nullable=False))
    description: str = Field(default="", title="Description", amis_form_item="textarea")
    status: bool = Field(None, title="status")
    articles: List["Article"] = Relationship(back_populates="category")

throw
RuntimeError: Passing primary_key is not supported when also passing a sa_column

sqlmodel                0.0.11
SQLAlchemy              1.4.50
@julianolm
Copy link

julianolm commented Apr 4, 2024

Thats strange. Look at this if statement in line 109 https://github.com/tiangolo/sqlmodel/blob/main/sqlmodel/main.py#L109

Here you can see where sqlmodel throws the Passing ... is not supported when also passing a sa_column error. But there you can see the fields you're not allowed to pass in case you are already passing sa_Column as one of Field's parameters.

Maybe fastapi-amis-admin is doing something under the hood and passing an sa_Column to your id Field definition. Just a guess, but don't know actually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants