Django

Code

Ticket #1802 (closed: fixed)

Opened 3 years ago

Last modified 2 years ago

changing description name gives error with

Reported by: mdt@emdete.de Assigned to: adrian
Milestone: Component: django.contrib.admin
Version: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

after changing the verbose_name, a manage.py syncdb gave an error:

Traceback (most recent call last):
  File "./manage.py", line 11, in ?
    execute_manager(settings)
  File "django/core/management.py", line 1237, in execute_manager
    execute_from_command_line(action_mapping)
  File "django/core/management.py", line 1163, in execute_from_command_line
    action_mapping[action]()
  File "django/core/management.py", line 473, in syncdb
    app=app, created_models=created_models)
  File "django/dispatch/dispatcher.py", line 347, in send
    sender=sender,
  File "django/dispatch/robustapply.py", line 47, in robustApply
    return receiver(*arguments, **named)
  File "django/contrib/auth/management.py", line 34, in create_permissions
    p.save()
  File "django/db/models/base.py", line 185, in save
    ','.join(placeholders)), db_values)
  File "django/db/backends/util.py", line 12, in execute
    return self.cursor.execute(sql, params)
  File "django/db/backends/sqlite3/base.py", line 74, in execute
    return Database.Cursor.execute(self, query, params)
pysqlite2.dbapi2.IntegrityError: columns content_type_id, codename are not unique

content of the table is:

sqlite> select * from auth_permission;
...
31|Can add TrainingsTagebuch|11|add_trainingstagebuch
32|Can change TrainingsTagebuch|11|change_trainingstagebuch
33|Can delete TrainingsTagebuch|11|delete_trainingstagebuch

executed sql is:

SELECT "auth_permission"."id","auth_permission"."name","auth_permission"."content_type_id","auth_permission"."codename" FROM "auth_permission" WHERE ("auth_permission"."codename" = ? AND "auth_permission"."name" = ? AND "auth_permission"."content_type_id" = ?) ['add_trainingstagebuch', u'Can add Eintrag im Trainingstagebuch', 11]
INSERT INTO "auth_permission" ("name","content_type_id","codename") VALUES (?,?,?) [u'Can add Eintrag im Trainingstagebuch', 11, 'add_trainingstagebuch']

because the name is used in the where lookup django does not find the record and tries to insert a new one.

Attachments

Change History

05/08/06 07:58:40 changed by mdt

fix in django/contrib/auth/management.py:31 instead of:

Permission.objects.get(name=name, codename=codename, content_type__pk=ctype.id)

use:

Permission.objects.get(codename=codename, content_type__pk=ctype.id)

perhaps one should add a way to reflect the new name also here.

06/19/06 23:44:27 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

(In [3172]) Fixed #1802 -- Fixed database integrity error when creating permission objects after renaming a model


Add/Change #1802 (changing description name gives error with)




Change Properties
Action