2008/9/11 Chris Stromberger <[EMAIL PROTECTED]>:
> Curious about using "unique" in a column definition of a model for a legacy
> db.  My assumption is that "unique" only comes into play during db creation,
> to create the index on the field, and thereafter uniqueness is enforced by
> the db?  Or does unique in a model affect creation of new model objects or
> anything else?
>
> Just wondering bcs I made a few columns unique on the db after the initial
> model creation.  Is it important to go back and add unique to the Django
> model in this case?

You can read in the documentation of the unique field option[1]:

"This is enforced at the database level and at the Django admin-form
level. 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."

About a legacy db where you put a unique constraint manually it is
recommended to put the option unique to the field so you get
a nice error in the Django forms  instead of an error screen.

Regards.

[1] http://docs.djangoproject.com/en/dev/ref/models/fields/#unique

-- 
Marcelo Ramos

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to