Force uniqueness on uuid

This commit is contained in:
Nico Schottelius 2020-02-23 11:59:09 +01:00
parent f8c29aa1d6
commit 1d1ae6fb3e
2 changed files with 20 additions and 1 deletions

View file

@ -0,0 +1,19 @@
# Generated by Django 3.0.3 on 2020-02-23 10:58
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
('opennebula', '0002_vm_uuid'),
]
operations = [
migrations.AlterField(
model_name='vm',
name='uuid',
field=models.UUIDField(default=uuid.uuid4, editable=False, unique=True),
),
]

View file

@ -6,7 +6,7 @@ from django.contrib.postgres.fields import JSONField
class VM(models.Model): class VM(models.Model):
vmid = models.IntegerField(primary_key=True) vmid = models.IntegerField(primary_key=True)
uuid = models.UUIDField(default=uuid.uuid4, editable=False) uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE) owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
data = JSONField() data = JSONField()