diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2013-02-15 09:00:55 +0800 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2013-02-15 09:02:14 +0800 |
| commit | bc6746ac303ab625f2bc6fc878bd63661c784a59 (patch) | |
| tree | 1c49723ae98e045e33b6a4bca763d32772ee98f9 /django/core | |
| parent | 1c086df50e76f1fd84e0d90bfb1d0b13468ba13b (diff) | |
[1.5.x] Fixed #19822 -- Added validation for uniqueness on USERNAME_FIELD on custom User models.
Thanks to Claude Peroz for the draft patch.
(cherry picked from commit f5e4a699ca0f58818acbdf9081164060cee910fa)
Diffstat (limited to 'django/core')
| -rw-r--r-- | django/core/management/validation.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/django/core/management/validation.py b/django/core/management/validation.py index c0452c5aa6..86a0df28fc 100644 --- a/django/core/management/validation.py +++ b/django/core/management/validation.py @@ -50,12 +50,16 @@ def get_validation_errors(outfile, app=None): # No need to perform any other validation checks on a swapped model. continue - # This is the current User model. Check known validation problems with User models + # If this is the current User model, check known validation problems with User models if settings.AUTH_USER_MODEL == '%s.%s' % (opts.app_label, opts.object_name): # Check that the USERNAME FIELD isn't included in REQUIRED_FIELDS. if cls.USERNAME_FIELD in cls.REQUIRED_FIELDS: e.add(opts, 'The field named as the USERNAME_FIELD should not be included in REQUIRED_FIELDS on a swappable User model.') + # Check that the username field is unique + if not opts.get_field(cls.USERNAME_FIELD).unique: + e.add(opts, 'The USERNAME_FIELD must be unique. Add unique=True to the field parameters.') + # Model isn't swapped; do field-specific validation. for f in opts.local_fields: if f.name == 'id' and not f.primary_key and opts.pk.name == 'id': |
