django 添加联合唯一索引

Django 添加联系唯一索引方法

联合唯一索引,指的是,多个键值相同时保持唯一,添加方法如下:

1
2
3
4
5
6
7
8
9
from django.db import models
class MyModel(models.Model):
name = models.CharField(max_length=200, verbose_name="name")
version = models.IntegerField(max_length=100, verbose_name="version")
class Meta():
verbose_name = "mymodel"
verbose_name_plural = "mymodel"
unique_together = (("name", "version"),)