Metadata.create_all
call with list of tables as argument fails with "TypeError: object of type 'InstrumentedAttribute' has no len()"
#910
Answered
by
joachimhuet
gmichaeljaison
asked this question in
Questions
-
First Check
Commit to Help
Example Codeimport sqlalchemy
import sqlmodel
class Session(sqlmodel.SQLModel, table=True):
uid: str = sqlmodel.Field(primary_key=True)
name: str
engine = sqlmodel.create_engine("sqlite:///dummy.db", echo=True)
sqlmodel.SQLModel.metadata.create_all(engine, [Session]) Description
Operating SystemmacOS Operating System DetailsNo response SQLModel Version0.0.16 Python VersionPython 3.12.2 Additional Context
|
Beta Was this translation helpful? Give feedback.
Answered by
joachimhuet
Apr 27, 2024
Replies: 1 comment
-
Yes, if you dive in the code you see that tables takes the table from metadata. ...
SQLModel.metadata.create_all(engine, tables=[SQLModel.metadata.tables["session"]]) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
YuriiMotov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, if you dive in the code you see that tables takes the table from metadata.
So you will have to use it like so in order to take the Table object and not the SQLModel: