In mssql, the names and json_data columns are made of varchar.
Since I want an nvarchar column, I specified type_ separately in the sa_column_kwargs option.
However, I confirmed that an error occurred in sqlalchemy.
This error seems to occur when the positional argumet and keyword argumet for type_ overlap.
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 1586, in __init__
raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: May not pass type_ positionally and as a keyword.
In this case, I would appreciate it if you could tell me what to do.
Which currently doesn't support Unicode. One option would be to add Unicode to the options supported by get_sqlalchemy_type, or to deal with the special case of receiving a type_ kwarg.
IMO allowing advanced users to pass through whatever they want via sa_column_kwargs is a better/more generic approach. I'll do a PR for that 👍
Edit: whoops this just occurred to me when I used it. Easier way to do this is to set the column type directly via sa_column:
Thank you so much for letting me know a solution that I can use right away. Options such as max_length or nullable should be specified again in the sa_column, but it's not a big problem right now.
Thank you @RobertRosca! Thank you SQLModel!
So setting sa_column worked like you wanted? If so could you close the issue? I'll also look into doing a PR to add this use case to the docs, with Unicode as an example.
Activity
RobertRosca commented on Nov 17, 2021
Looked into this a bit.
When you pass sa_column_kwargs those get propagated through to when the sa column is created here:
https://github.com/tiangolo/sqlmodel/blob/02da85c9ec39b0ebb7ff91de3045e0aea28dc998/sqlmodel/main.py#L447
The issue happens since you're passing type_ = Unicode as a keyword argument, but SQLModel already passes sa_type through as the positional argument.
The sa_type variable is found by:
https://github.com/tiangolo/sqlmodel/blob/02da85c9ec39b0ebb7ff91de3045e0aea28dc998/sqlmodel/main.py#L373-L409
Which currently doesn't support Unicode. One option would be to add Unicode to the options supported by get_sqlalchemy_type, or to deal with the special case of receiving a type_ kwarg.
IMO allowing advanced users to pass through whatever they want via sa_column_kwargs is a better/more generic approach. I'll do a PR for that 👍
Edit: whoops this just occurred to me when I used it. Easier way to do this is to set the column type directly via sa_column:
phi-friday commented on Nov 18, 2021
Thank you so much for letting me know a solution that I can use right away. Options such as max_length or nullable should be specified again in the sa_column, but it's not a big problem right now.
Thank you @RobertRosca! Thank you SQLModel!
RobertRosca commented on Nov 18, 2021
😁 glad to help!
So setting sa_column worked like you wanted? If so could you close the issue? I'll also look into doing a PR to add this use case to the docs, with Unicode as an example.
phi-friday commented on Nov 18, 2021
@RobertRosca
Of course!
Thank you!
tiangolo commented on Oct 29, 2023
In SQLModel 0.0.11 you can now set sa_type with the SQLAlchemy type. 🎉
fbuccioni commented on Mar 21, 2026
I have done this by monkey patching:
Maybe it could be a global config system or flag to use Unicode in AutoStrings