擅长:python、mysql、java
<p>您需要在meta类中使用<code>unique_together</code></p>
<pre><code>class Student(models.Model):
...
class Meta:
unique_together = ("grade", "rollno")
</code></pre>
<p>提供详细文档<a href="https://docs.djangoproject.com/en/dev/ref/models/options/#django.db.models.Options.unique_together" rel="nofollow noreferrer">here</a></p>