-
First Check
Commit to Help
Example CodeOriginal: class User(UserBase, table=True):
id: uuid.UUID = Field(
sa_column=Column(UUIDC, primary_key=True, default=uuid.uuid4),
) Modified, modified to work properly: from sqlalchemy import Uuid, Column
UUIDC = Uuid(as_uuid=False)
# Database model, database table inferred from class name
class User(UserBase, table=True):
id: uuid.UUID = Field(
sa_column=Column(UUIDC, primary_key=True, default=uuid.uuid4),
) So, my question is: Is this the right tweak? DescriptionI want to use mysql, and also use uuid for the primary key. I have adapted the engine to mysql+pymysql. and started it successfully, but after starting it, accessing the front-end gives me the following error.
Operating SystemLinux Operating System DetailsUbuntu 24.04 Python Version3.10 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You may have a use case for it but is your application globally distributed where a centralized generation of a unique ID for the primary key will be a bottleneck? |
Beta Was this translation helpful? Give feedback.
You may have a use case for it but is your application globally distributed where a centralized generation of a unique ID for the primary key will be a bottleneck?
If your answer is NO, I suggests not to use
UUID
. AnIDENTITY
is much easier to work with. On a straight sprint, comparing 4 bytes ofINT32
is going to be 4X faster than comparing 16 bytes ofUUID
.