First Check
Commit to Help
Example Code
from typing import Optional
from sqlmodel import Field, Session, SQLModel, create_engine
class Hero(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
# This should not be nullable
name: Optional[str] = Field(default=None, nullable=False)
hero = Hero()
engine = create_engine("sqlite:///database.db")
SQLModel.metadata.create_all(engine)
with Session(engine) as session:
session.add(hero)
session.commit()
session.refresh(hero)
print(hero)
Description
- Create a hero model with a non-nullable column by assigning it to
Field(nullable=True)
- Create a hero instance without setting the column
- Save the instance to the DB. Should get an error but the hero instance saves successfully.
I believe this issue was introduced here: 9830ee0#r82434170
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.7
Python Version
Python 3.10.5
Additional Context
No response
First Check
Commit to Help
Example Code
Description
Field(nullable=True)I believe this issue was introduced here: 9830ee0#r82434170
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.7
Python Version
Python 3.10.5
Additional Context
No response