amisadmin / fastapi-amis-admin

FastAPI-Amis-Admin is a high-performance, efficient and easily extensible FastAPI admin framework. Inspired by django-admin, and has as many powerful functions as django-admin.
http://docs.amis.work
Apache License 2.0
1.05k stars 154 forks source link

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

Open felixjichao opened 9 months ago

felixjichao commented 9 months ago

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 commented 6 months ago

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