Title: Order of columns in the table created does not have 'id' first, despite the order in the SQLModel. Looks like it's prioritising fields with sa_column · Issue #542 · fastapi/sqlmodel · GitHub
Open Graph Title: Order of columns in the table created does not have 'id' first, despite the order in the SQLModel. Looks like it's prioritising fields with sa_column · Issue #542 · fastapi/sqlmodel
X Title: Order of columns in the table created does not have 'id' first, despite the order in the SQLModel. Looks like it's prioritising fields with sa_column · Issue #542 · 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/542
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Order of columns in the table created does not have 'id' first, despite the order in the SQLModel. Looks like it's prioritising fields with sa_column","articleBody":"### First Check\r\n\r\n- [X] I added a very descriptive title to this issue.\r\n- [X] I used the GitHub search to find a similar issue and didn't find it.\r\n- [X] I searched the SQLModel documentation, with the integrated search.\r\n- [X] I already searched in Google \"How to X in SQLModel\" and didn't find any information.\r\n- [X] I already read and followed all the tutorial in the docs and didn't find an answer.\r\n- [X] I already checked if it is not related to SQLModel but to [Pydantic](https://github.com/samuelcolvin/pydantic).\r\n- [X] I already checked if it is not related to SQLModel but to [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy).\r\n\r\n### Commit to Help\r\n\r\n- [X] I commit to help with one of those options 👆\r\n\r\n### Example Code\r\n\r\n```python\r\nfrom sqlmodel import Field, SQLModel, JSON, Column, Time\r\n\r\nclass MyTable(SQLModel, table=True):\r\n id: int | None = Field(default=None, primary_key=True)\r\n name: str\r\n type: str\r\n slug: str = Field(index=True, unique=True)\r\n resource_data: dict | None = Field(default=None, sa_column=Column(JSON)) # type: ignore\r\n\r\n\r\n# ... create engine\r\n\r\nSQLModel.metadata.create_all(engine)\r\n```\r\n\r\n\r\n### Description\r\n\r\nThe CREATE table script generated for the model above ends up putting resource_data as the first column, instead of preserving the natural order of 'id' first\r\n\r\n```\r\nCREATE TABLE mytable (\r\n resource_data JSON, \u003c----- why is this the FIRST column created?\r\n id SERIAL NOT NULL, \r\n name VARCHAR NOT NULL, \r\n type VARCHAR NOT NULL, \r\n slug VARCHAR NOT NULL, \r\n PRIMARY KEY (id)\r\n)\r\n```\r\n\r\nThis feels unusual when I inspect my postgresql tables in a db tool like pgAdmin.\r\n\r\nHow do I ensure the table is created with the 'natural' order?\r\n\r\n### Operating System\r\n\r\nmacOS\r\n\r\n### Operating System Details\r\n\r\n_No response_\r\n\r\n### SQLModel Version\r\n\r\n0.0.8\r\n\r\n### Python Version\r\n\r\n3.11.1\r\n\r\n### Additional Context\r\n\r\n_No response_","author":{"url":"https://github.com/epicwhale","@type":"Person","name":"epicwhale"},"datePublished":"2023-01-29T14:11:08Z","url":"https://github.com/fastapi/sqlmodel/issues/542"}
| 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:f69d8431-7dea-359c-5df8-0b3a5c658db5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8D6C:24FA46:B2F1E0:F33989:6AFE6969 |
| html-safe-nonce | dfbe71f19cc25976bba755e6200b34071ee6edbacb29ea1b34e63ff515eebdde |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RDZDOjI0RkE0NjpCMkYxRTA6RjMzOTg5OjZBRkU2OTY5IiwidmlzaXRvcl9pZCI6IjI3MDY5MTQ0MDkwNjg4OTU3NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b0e86c70a61a3d542f333c06b79c9dcd3c6b9d67ca538f011c62b5b81bca669e |
| hovercard-subject-tag | issue:1561306134 |
| 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/542/issue_layout |
| twitter:image | https://opengraph.githubassets.com/aafd7356d69ac949080de2abf6a0e6632fb99c1018c76bb27c67c51852d0dc76/fastapi/sqlmodel/issues/542 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/aafd7356d69ac949080de2abf6a0e6632fb99c1018c76bb27c67c51852d0dc76/fastapi/sqlmodel/issues/542 |
| 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 | epicwhale |
| hostname | github.com |
| expected-hostname | github.com |
| None | b3c0f155eafc27e60db6e254d1ffff0e072e9ab3b4018a5ee518797c19d89f86 |
| 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 | 4a10310af51a1bfffbedc4fd81cb582acf0cb0ff |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width