sqlmodel
sqlmodel copied to clipboard
Tables are created using latin1 charset, even if connection string to database specifies utf8mb4
First Check
- [X] I added a very descriptive title to this issue.
- [X] I used the GitHub search to find a similar issue and didn't find it.
- [X] I searched the SQLModel documentation, with the integrated search.
- [X] I already searched in Google "How to X in SQLModel" and didn't find any information.
- [X] I already read and followed all the tutorial in the docs and didn't find an answer.
- [X] I already checked if it is not related to SQLModel but to Pydantic.
- [X] I already checked if it is not related to SQLModel but to SQLAlchemy.
Commit to Help
- [X] I commit to help with one of those options ð
Example Code
engine = create_engine(
f'mysql+pymysql://{user}:{password}@{host}:3306/{database}?charset=utf8mb4')
class ControlledVocabulary(SQLModel, table=True):
row: Optional[int] = Field(default=None, primary_key=True)
cvID: str = Field(max_length=32)
gracenote_updateID: int
gracenote_updateDate: str
type: str = Field(max_length=32)
id: int
language: str = Field(max_length=16)
value: str = Field(max_length=128)
extended: Optional[str] = Field(max_length=128)
Then in MySQL, show create table controlledvocabulary
CREATE TABLE `controlledvocabulary` (
`row` int(11) NOT NULL AUTO_INCREMENT,
`cvID` varchar(32) NOT NULL,
`gracenote_updateID` int(11) NOT NULL,
`gracenote_updateDate` varchar(255) NOT NULL,
`type` varchar(32) NOT NULL,
`id` int(11) NOT NULL,
`language` varchar(16) NOT NULL,
`value` varchar(128) NOT NULL,
`extended` varchar(128) DEFAULT NULL,
PRIMARY KEY (`row`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
Description
The table is being created as latin1 and not utf8mb4.
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.6
Python Version
3.9.6
Additional Context
No response
One quick look at the source code shows that the custom create_engine function literally passes the url argument unchanged to the corresponding SQLAlchemy function.
Please make a little effort, instead of cluttering up the issues. The template specifically asks you to confirm that you "already checked if it is not related to SQLModel but to SQLAlchemy."
I suggest you confirm that the behavior is the same with "vanilla" SQLAlchemy and close this issue.
@rkulagowski please try replicating the example with pure SQLAlchemy, the error is probably there somewhere. It might also be worth trying the lastest version of SQLModel that allows you to use the current latest of SQLAlchemy.
@daniil-berg thanks a lot for the help! :bow: :cake:
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.