UUIDs cannot be queried using get as primary key
See original GitHub issueRecently, I started using ormar instead of tortoise-orm in my projects, but have encountered a strange problem, if I use uuid as the primary key of a model, I can’t match the data when using get query.
example:
class MainMeta(ormar.ModelMeta):
metadata = metadata
database = database
class UserModel(ormar.Model):
class Meta(MainMeta):
tablename = "usermodel"
id: ormar.UUID(primary_key=True)
username = ormar.String(index=True, unique=True, null=False, max_length=255)
email = ormar.String(index=True, unique=True, nullable=False, max_length=255)
hashed_password = ormar.String(null=False, max_length=255)
is_active = ormar.Boolean(default=True, nullable=False)
is_superuser = ormar.Boolean(default=False, nullable=False)
user = await UserModel.objects.first()
await UserModel.objects.get(id=user.id) # raise NoMatch
await UserModel.objects.get(username=user.username) # Match user
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
UUID or GUID as Primary Keys? Be Careful! | by Tom Harrison
Reasons UUIDs May Not be Good · Don't be naive · UUIDs are a pain · Planning for real scaling · Primary keys...
Read more >Be Careful with UUID or GUID as Primary Keys - Hacker News
Badly chosen surrogate keys or time-series clustering can lead to performance problems that are just as severe depending on your access patterns ...
Read more >Cannot use UUID as a primary key: Uuid: diesel::Expression is ...
I found some old post that suggested that the field might be nullable but id is the PRIMARY KEY in my table up.sql,...
Read more >Auto-generated primary keys: UUID, serial or identity column?
This article explores the old question what to use for autogenerated primary keys: UUID, serial or identity column?
Read more >UUIDs are Popular, but Bad for Performance — Let's Discuss
The tables now use integers as primary keys. This mapping removes nearly all the scalability concerns of using UUID values.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is the table structure corresponding to the usermodel
Problem solved, thank you for such a quick response and fix!