Django migration with uuid field generates duplicated values

Here is an example doing everything in one single migration thanks to a RunPython call. # -*- coding: utf-8 -* from __future__ import unicode_literals from django.db import migrations, models import uuid def create_uuid(apps, schema_editor): Device = apps.get_model(‘device_app’, ‘Device’) for device in Device.objects.all(): device.uuid = uuid.uuid4() device.save() class Migration(migrations.Migration): dependencies = [ (‘device_app’, ‘XXXX’), ] operations … Read more

Store UUID v4 in MySQL

Store it as VARCHAR(36) if you’re looking to have an exact fit, or VARCHAR(255) which is going to work out with the same storage cost anyway. There’s no reason to fuss over bytes here. Remember VARCHAR fields are variable length, so the storage cost is proportional to how much data is actually in them, not … Read more

How to generate a random UUID which is reproducible (with a seed) in Python

Almost there: uuid.UUID(int=rd.getrandbits(128)) This was determined with the help of help: >>> help(uuid.UUID.__init__) Help on method __init__ in module uuid: __init__(self, hex=None, bytes=None, bytes_le=None, fields=None, int=None, version=None) unbound uuid.UUID method Create a UUID from either a string of 32 hexadecimal digits, a string of 16 bytes as the ‘bytes’ argument, a string of 16 bytes … Read more

What’s your opinion on using UUIDs as database row identifiers, particularly in web apps?

I can’t say about the web side of your question. But uuids are great for n-tier applications. PK generation can be decentralized: each client generates it’s own pk without risk of collision. And the speed difference is generally small. Make sure your database supports an efficient storage datatype (16 bytes, 128 bits). At the very … Read more

How to store uuid as number?

If I understand correctly, you’re using UUIDs in your primary column? People will say that a regular (integer) primary key will be faster , but there’s another way using MySQL’s dark side. In fact, MySQL is faster using binary than anything else when indexes are required. Since UUID is 128 bits and is written as … Read more

What are the project GUIDs in a Visual Studio solution file used for?

Project persistence block in a solution file has the following format: Project(“{project type GUID}”) = “<Project name>”, “<project file location>”, “{<Unique project GUID>}” EndProject So it’s expected that first GUID is non-unique, it uniquely identifies Visual Studio package that handles this type of projects. The GUID you posted is interesting – it looks like mangled … Read more

A TypeScript GUID class? [closed]

Updated Answer This is now something you can do natively in JavaScript/TypeScript with crypto.randomUUID(). Here’s an example generating 20 UUIDs. for (let i = 0; i < 20; i++) { let id = crypto.randomUUID(); console.log(id); } Original Answer There is an implementation in my TypeScript utilities based on JavaScript GUID generators. Here is the code: … Read more