Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#24299 closed Bug (fixed)

`migrate auth` throws django.db.utils.IntegrityError

Reported by: Sergey Fedoseev Owned by: nobody
Component: Migrations Version: 1.8alpha1
Severity: Normal Keywords: 1.8-beta
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

do migrate auth on clean DB

Operations to perform:
  Apply all migrations: auth
Running migrations:
  Rendering model states... DONE
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
    output = self.handle(*args, **options)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 217, in handle
    emit_post_migrate_signal(created_models, self.verbosity, self.interactive, connection.alias)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/core/management/sql.py", line 280, in emit_post_migrate_signal
    using=db)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 201, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 87, in create_permissions
    ctype = ContentType.objects.db_manager(using).get_for_model(klass)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 78, in get_for_model
    model=opts.model_name,
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/db/models/manager.py", line 127, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/db/models/query.py", line 404, in get_or_create
    return self._create_object_from_params(lookup, params)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/db/models/query.py", line 444, in _create_object_from_params
    six.reraise(*exc_info)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/db/models/query.py", line 436, in _create_object_from_params
    obj = self.create(**params)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/db/models/query.py", line 345, in create
    obj.save(force_insert=True, using=self.db)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/db/models/base.py", line 696, in save
    force_update=force_update, update_fields=update_fields)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/db/models/base.py", line 724, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/db/models/base.py", line 808, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/db/models/base.py", line 847, in _do_insert
    using=using, raw=raw)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/db/models/manager.py", line 127, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/db/models/query.py", line 917, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 964, in execute_sql
    cursor.execute(sql, params)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 80, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: null value in column "name" violates not-null constraint
DETAIL:  Failing row contains (1, null, auth, permission).

Change History (9)

comment:1 by Markus Holtermann, 10 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Marten Kenbeek, 10 years ago

Version: master1.8alpha1

The removel of ContentType.name as a field in b4ac23290772e0c11379eb2dfb81c750b7052b66 introduced this bug in 1.8. ContentType.get_for_model can't be used at all for non-existing content types until the 0002_remove_content_type_name migration is applied.

Making the first migrations of contrib.auth and contrib.admin dependant on 0002_remove_content_type_name solves the issue for those apps, but not necessarily for all apps that use content types.

Version 0, edited 10 years ago by Marten Kenbeek (next)

comment:3 by Tim Graham, 10 years ago

Keywords: 1.8-beta added
Needs tests: set

comment:4 by Tim Graham, 10 years ago

Needs tests: unset

comment:5 by Tim Graham <timograham@…>, 10 years ago

In d392c1e150a46aca72e37263c44c034d92a79f79:

Refs #24299 -- Made contenttypes migrations signal handler more robust.

comment:6 by Tim Graham <timograham@…>, 10 years ago

In 870d900cdcd29564bcc7f47cc67d51af2617f614:

[1.8.x] Refs #24299 -- Made contenttypes migrations signal handler more robust.

Backport of d392c1e150a46aca72e37263c44c034d92a79f79 from master

comment:7 by Tim Graham, 10 years ago

Markus suggested to also add a migration to ensure all contenttypes 0002 is applied before sending the post_migrate signal for auth.

comment:8 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: newclosed

In 4538cbf17d4391cda22d76bc6ac69f228f7400f2:

Fixed #24299 -- Added an auth migration to ensure contenttypes is migrated.

Without this migration, the auth signal handlers will fail if migrating
only auth.

comment:9 by Tim Graham <timograham@…>, 10 years ago

In 77e3f7dd586908b6c78d9718bbea65846e20e180:

[1.8.x] Fixed #24299 -- Added an auth migration to ensure contenttypes is migrated.

Without this migration, the auth signal handlers will fail if migrating
only auth.

Backport of 4538cbf17d4391cda22d76bc6ac69f228f7400f2 from master

Note: See TracTickets for help on using tickets.
Back to Top