question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support auto generate UUID for non pk field

See original GitHub issue

First, Thank you for support nice software 😃 I find that UUIDField only auto generate UUID4 only that field is primary key. How about support auto generate UUID key for non pk field?

Maybe we can use like below

uid = fields.UUIDField(auto_generate=True) # default : False

Also, I’m not good at orm and database well. I want to hear about other’s opinions. I really appreciate if anyone answer to me! Thank you 👍

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
abondarcommented, Jan 30, 2020

Hi!

Actually, for pk uuid fields generation is done inside of Tortoise just like that:

    def __init__(self, **kwargs) -> None:
        if kwargs.get("pk", False):
            if "default" not in kwargs:
                kwargs["default"] = uuid4
        super().__init__(**kwargs)

So, if you wanna same behaviour for non-pk uuid field you just have to do it like that:

from uuid import uuid4
...
uid = fields.UUIDField(default=uuid4)
1reaction
grigicommented, Jan 31, 2020

Yes, I have been having to do many support queries where the docs either had something missing, or was hard to find. We need doc guidelines.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Auto generate UUID value for non-primary key using JPA
I have a non-primary key of type UUID which I want to auto generate on call of save method. I annotated the attribute...
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 >
How to generate UUIDs as primary keys with Hibernate
Generating UUIDs using JPA 3.1​​ Since JPA 3.1, you can annotate a primary key attribute with @GeneratedValue and set the strategy to GenerationType....
Read more >
Enable <generator> tag for non primary key columns that are ...
Our current datamodel has a UUID char 32 as the primary key and ID column which is a sequence for Oracle and an...
Read more >
SQL Primary Key - UUID or Auto Increment Integer / Serial?
For database like MySQL, Oracle, which uses clustered primary key, version 4 randomly generated UUID will hurt insertion performance if used as ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found