From fb1c01b1038cbba421aaaf5b53da5bb507cc9b48 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Tue, 20 Jun 2006 04:44:27 +0000 Subject: [PATCH] Fixed #1802 -- Fixed database integrity error when creating permission objects after renaming a model git-svn-id: http://code.djangoproject.com/svn/django/trunk@3172 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/auth/management.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/django/contrib/auth/management.py b/django/contrib/auth/management.py index c4c315eb21..1a07417f1d 100644 --- a/django/contrib/auth/management.py +++ b/django/contrib/auth/management.py @@ -25,11 +25,9 @@ def create_permissions(app, created_models): for klass in app_models: ctype = ContentType.objects.get_for_model(klass) for codename, name in _get_all_permissions(klass._meta): - try: - Permission.objects.get(name=name, codename=codename, content_type__pk=ctype.id) - except Permission.DoesNotExist: - p = Permission(name=name, codename=codename, content_type=ctype) - p.save() + p, created = Permission.objects.get_or_create(codename=codename, content_type__pk=ctype.id, + defaults={'name': name, 'content_type': ctype}) + if created: print "Adding permission '%s'" % p def create_superuser(app, created_models):