-
-
Notifications
You must be signed in to change notification settings - Fork 769
Closed
Labels
Description
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, 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