You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In SQLAlchemy, I was able to get the string representation of the column name by using .key. (Documentation) .key can also be used in SQLModel, but it does not behave correctly in VSCode (and probably other IDEs as well).
Each member of SQLModel behaves as if it were the type stored in that column.
For example, an int column naturally does not have a .key .
Therefore, using .key results in it being displayed as Any.
In SQLAlchemy, .key was displayed as str.
Whether or not to use Field() also affects how it behaves in VSCode.
In this case, a Pylint error stating “Instance of ‘FieldInfo’ has no ‘key’ member” also appears.
The string representation of column names is necessary when using DataFrames, etc.
When referencing the age column of a DataFrame, I want to use like Hero.age.key instead of “age” . This is because IDE support is available when refactoring column names.
How can I get a specific column name from SQLModel?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
In SQLAlchemy, I was able to get the string representation of the column name by using
.key
. (Documentation).key
can also be used in SQLModel, but it does not behave correctly in VSCode (and probably other IDEs as well).Each member of SQLModel behaves as if it were the type stored in that column.
For example, an
int
column naturally does not have a.key
.Therefore, using
.key
results in it being displayed asAny
.In SQLAlchemy,
.key
was displayed asstr
.Whether or not to use
Field()
also affects how it behaves in VSCode.In this case, a Pylint error stating “Instance of ‘FieldInfo’ has no ‘key’ member” also appears.
The string representation of column names is necessary when using DataFrames, etc.
When referencing the age column of a DataFrame, I want to use like
Hero.age.key
instead of“age”
. This is because IDE support is available when refactoring column names.How can I get a specific column name from SQLModel?
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.24
Python Version
Python 3.13.3
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions