First Check
Commit to Help
Example Code
from pydantic import SecretStr
from sqlmodel import Field, Session, SQLModel, create_engine
class A(SQLModel, table=True):
id: int = Field(primary_key=True)
secret: SecretStr
engine = create_engine("sqlite://")
SQLModel.metadata.create_all(engine)
# sqlalchemy.exc.CompileError: (in table 'a', column 'secret'): Can't generate DDL for NullType(); did you forget to specify a type on this Column?
Description
- Create a class with a
pydantic.SecretStr field
- Create the table
- Execution fails with
Can't generate DDL for NullType() exception
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
3.9.6
Additional Context
We can specify the column type manually, but it fails with another error:
from pydantic import SecretStr
from sqlmodel import Column, Field, Session, String, SQLModel, create_engine
class A(SQLModel, table=True):
id: int = Field(primary_key=True)
secret: SecretStr = Field(sa_column=Column(String))
engine = create_engine("sqlite://")
SQLModel.metadata.create_all(engine)
with Session(engine) as session:
a = A(id=1, secret="secret")
session.add(a)
session.commit()
# sqlalchemy.exc.InterfaceError: (sqlite3.InterfaceError) Error binding parameter 0 - probably unsupported type.
# [SQL: INSERT INTO a (secret, id) VALUES (?, ?)]
# [parameters: (SecretStr('**********'), 1)]
First Check
Commit to Help
Example Code
Description
pydantic.SecretStrfieldCan't generate DDL for NullType()exceptionOperating System
macOS
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
3.9.6
Additional Context
We can specify the column type manually, but it fails with another error: