Title: Easy to make mistakes when defining nullable (Field() vs Field(Column()) · Issue #464 · fastapi/sqlmodel · GitHub
Open Graph Title: Easy to make mistakes when defining nullable (Field() vs Field(Column()) · Issue #464 · fastapi/sqlmodel
X Title: Easy to make mistakes when defining nullable (Field() vs Field(Column()) · Issue #464 · fastapi/sqlmodel
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...
Open Graph 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...
X 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 searc...
Opengraph URL: https://github.com/fastapi/sqlmodel/issues/464
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Easy to make mistakes when defining nullable (Field() vs Field(Column())","articleBody":"### First Check\n\n- [X] I added a very descriptive title to this issue.\n- [X] I used the GitHub search to find a similar issue and didn't find it.\n- [X] I searched the SQLModel documentation, with the integrated search.\n- [X] I already searched in Google \"How to X in SQLModel\" and didn't find any information.\n- [X] I already read and followed all the tutorial in the docs and didn't find an answer.\n- [X] I already checked if it is not related to SQLModel but to [Pydantic](https://github.com/samuelcolvin/pydantic).\n- [X] I already checked if it is not related to SQLModel but to [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy).\n\n### Commit to Help\n\n- [X] I commit to help with one of those options 👆\n\n### Example Code\n\n```python\nHere a sample model:\r\n\r\n\r\nclass FooDB(SQLModel, table=True):\r\n id: int = Field(primary_key=True, nullable=False)\r\n datetime_1: datetime = Field(sa_column=Column(DateTime), nullable=False)\r\n datetime_2: datetime = Field(sa_column=Column(DateTime, nullable=False))\r\n\r\n string_1: str = Field(sa_column=Column(String(50)))\r\n string_2: str = Field(max_length=50)\r\n```\r\nAlembic creates the table as following:\r\n```\r\n\r\n op.create_table(\r\n \"foodb\",\r\n sa.Column(\"datetime_1\", sa.DateTime(), nullable=True),\r\n sa.Column(\"datetime_2\", sa.DateTime(), nullable=False),\r\n sa.Column(\"string_1\", sa.String(length=50), nullable=True),\r\n sa.Column(\"string_2\", sqlmodel.sql.sqltypes.AutoString(length=50), nullable=False),\r\n sa.PrimaryKeyConstraint(\"id\"),\r\n )\r\n\r\n```\n```\n\n\n### Description\n\nI had some surprises when looking closer at what data my tables actually accept vs. what I saw in my models.py. I find that it is very easy that one thinks one is doing the right thing (while looking at the pydantic/sqlmodel docs), but the definition does actually never make it into the database.\r\n\r\nIn my sample model I would have expected that the nullable-Attribute would lead to the same in each pair.\r\n \r\nRelated to https://github.com/tiangolo/sqlmodel/issues/420\n\n### Operating System\n\nLinux\n\n### Operating System Details\n\n_No response_\n\n### SQLModel Version\n\n0.0.8\n\n### Python Version\n\nPython 3.10.7\n\n### Additional Context\n\n_No response_","author":{"url":"https://github.com/martin-greentrax","@type":"Person","name":"martin-greentrax"},"datePublished":"2022-10-10T10:32:54Z","url":"https://github.com/fastapi/sqlmodel/issues/464"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4d78b40d-8064-ef50-232c-35242b73941d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D082:222268:A4CDA8:E69EBB:6AFE20AF |
| html-safe-nonce | 554fbbfcf8a8532eadf6f0e5df3a08687375e1e2077a2214c4ba34620ae1669b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMDgyOjIyMjI2ODpBNENEQTg6RTY5RUJCOjZBRkUyMEFGIiwidmlzaXRvcl9pZCI6IjQ1OTA5OTQ3OTYyMzA2MTUyMTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b722f177c7bc93fa7a855b4c633c71980154af03379e4501f1c07d1bf5c30a01 |
| hovercard-subject-tag | issue:1402952386 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/fastapi/sqlmodel/464/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e9f9ef9cf1a939635da83925bf3b643a56a275c7376458f28bdc5321f00f38a2/fastapi/sqlmodel/issues/464 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e9f9ef9cf1a939635da83925bf3b643a56a275c7376458f28bdc5321f00f38a2/fastapi/sqlmodel/issues/464 |
| og:image:alt | 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... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | martin-greentrax |
| hostname | github.com |
| expected-hostname | github.com |
| None | e973f9ec3625f3faad8cac5c2d11a214b7ffe45f3cc563b828459b290ecaeed3 |
| turbo-cache-control | no-preview |
| go-import | github.com/fastapi/sqlmodel git https://github.com/fastapi/sqlmodel.git |
| octolytics-dimension-user_id | 156354296 |
| octolytics-dimension-user_login | fastapi |
| octolytics-dimension-repository_id | 399495186 |
| octolytics-dimension-repository_nwo | fastapi/sqlmodel |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 399495186 |
| octolytics-dimension-repository_network_root_nwo | fastapi/sqlmodel |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 1f92c367595b9190e0be293896078033886b1913 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width