tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.54k stars 374 forks source link

CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci #1191

Open dyuzhou opened 2 years ago

dyuzhou commented 2 years ago

Describe the bug CHARSET=utf8mb4,COLLATE=utf8mb4_general_ci They are configured in the mysql configuration file and the database used, but after I use tortoise-orm to create the table, they all use CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

To Reproduce Steps to reproduce the behavior, preferably a small code snippet.

Expected behavior I want the table he created to also use CHARSET=utf8mb4,COLLATE=utf8mb4_general_ci,Is it a problem of aiomysql or tortoise-orm? what should I do

long2ice commented 2 years ago

How did you create the table?

dyuzhou commented 2 years ago

你是如何创建表格的?

class Hospital(Model): class Meta: table = 'hospital'

id = fields.CharField(max_length=50, pk=True, index=True, description='医院ID')
name = fields.CharField(max_length=255, default=None, null=True, description='医院名称')
alias = fields.TextField(default=None, null=True, description='医院-所有名称名称')
create_time = fields.DatetimeField(null=False, auto_now_add=True, description='创建时间')
update_time = fields.DatetimeField(null=False, auto_now=True, description='更新时间')
table_description = '医院表'

async def init(): await Tortoise.init( db_url=settings.db_url, modules={'models': ['models.model']} ) await Tortoise.generate_schemas()

async def close_db(): await Tortoise.close_connections()

if name == 'main':

创建数据表

from tortoise import run_async
run_async(init())
long2ice commented 2 years ago

Tortoise will not set that, you can check other

frank2088 commented 2 years ago

Tortoise can set CHARSET, but not support COLLATE. you can see function "_table_generate_extra " in "site-packages\tortoise\backends\mysql\schema_generator.py"

sharkcheung commented 1 year ago

Can this issues be solved?