`Field(nullable=True)` is ignored due to recent changes released in version 0.0.7
See original GitHub issueFirst 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: https://github.com/tiangolo/sqlmodel/commit/9830ee0d8991ffc068ffb72ccead2427c84e58ee#r82434170
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.7
Python Version
Python 3.10.5
Additional Context
No response
Issue Analytics
- State:
- Created a year ago
- Comments:11 (10 by maintainers)
Top Results From Across the Web
npm install fails with NPM 7 #19957 - angular/angular-cli
Creating a new Angular project with the Angular CLI ( ng new ) fails when using the latest version of npm (7.5.x). Error...
Read more >Change nullable property of column in spark dataframe
I want to make 'nullable = true' for each one of these variable. How do I declare that from the start or switch...
Read more >typeorm: CHANGELOG
This change is due to type-safety improvement new where signature brings. order in FindOptions (used in find* methods) doesn't support ordering by relations ......
Read more >Fix / Feature List for IBM Financial Transaction Manager ...
Content. The following is a complete list of the fixes and features for FTM V3. 0.0, with the most recent fix first. AuxStatus...
Read more >npm fails to install - Google Groups
Or are you trying to launch an Appium\nserver from a script with a custom app? If so you can start Appium without\ngrunt from...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I assumed @tiangolo would squash the commits before merging the PR. But I will commit to your PR.
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.