Django Model Field Options: unique

By: Dusty Arlia
Published on Friday, March 14, 2014, 09:51 AM
Last Updated on Friday, July 17, 2015 at 3:55 PM
Total Updates: 2

The unique field option determines whether a field in a table should be unique. If unique=True, then this field must be unique throughout the table. This is enforced at the database level and by model validation. If you try to save a model with a duplicate value in a unique field, a django.db.IntegrityError will be raised by the model’s save() method. When the value of unique is set to True, you don’t need to specify db_index. This is because unique implies the creation of an index. This option is not valid on ManyToManyField, OneToOneField, and FileField field types.

Comments:

Ad:

Ad: