Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#21872 closed Bug (fixed)

With custom User, test database is not created due to missing auth.Group relation

Reported by: lwarx Owned by: Andrew Godwin <andrew@…>
Component: Migrations Version: 1.7-alpha-1
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


As described here:

I have custom User model and it worked fine at least on 1.5. On 1.7a1 my application works too, but I can't run any tests - database is not created due to missing auth.Group relation ("ValueError: Related model 'auth.Group' cannot be resolved").

Below are traceback

Traceback (most recent call last):
  File "src/", line 10, in <module>
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/", line 427, in execute_from_command_line
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/", line 419, in execute
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/commands/", line 50, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/commands/", line 71, in execute
    super(Command, self).execute(*args, **options)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/", line 337, in execute
    output = self.handle(*args, **options)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/commands/", line 88, in handle
    failures = test_runner.run_tests(test_labels)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/test/", line 147, in run_tests
    old_config = self.setup_databases()
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/test/", line 109, in setup_databases
    return setup_databases(self.verbosity, self.interactive, **kwargs)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/test/", line 299, in setup_databases
    verbosity, autoclobber=not interactive)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/backends/", line 367, in create_test_db
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/", line 167, in call_command
    return klass.execute(*args, **defaults)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/", line 337, in execute
    output = self.handle(*args, **options)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/commands/", line 145, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/migrations/", line 60, in migrate
    self.apply_migration(migration, fake=fake)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/migrations/", line 94, in apply_migration
    migration.apply(project_state, schema_editor)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/migrations/", line 97, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/migrations/operations/", line 28, in database_forwards
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/backends/", line 256, in create_model
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/backends/", line 182, in create_model
    definition, extra_params = self.column_sql(model, field)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/backends/", line 109, in column_sql
    db_params = field.db_parameters(connection=self.connection)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/models/fields/", line 1707, in db_parameters
    return {"type": self.db_type(connection), "check": []}
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/models/fields/", line 1698, in db_type
    rel_field = self.related_field
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/models/fields/", line 1605, in related_field
    return self.foreign_related_fields[0]
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/models/fields/", line 1367, in foreign_related_fields
    return tuple(rhs_field for lhs_field, rhs_field in self.related_fields)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/models/fields/", line 1354, in related_fields
    self._related_fields = self.resolve_related_fields()
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/models/fields/", line 1339, in resolve_related_fields
    raise ValueError('Related model %r cannot be resolved' %
ValueError: Related model 'auth.Group' cannot be resolved

and debug context

   1339         if isinstance(, six.string_types):
-> 1340             raise ValueError('Related model %r cannot be resolved' %
   1341         related_fields = []

ipdb> six.string_types
(<type 'basestring'>,)
ipdb> self.model
<class '__fake__.User_groups'>

Test machine: OS X Mavericks, Python 2.7.6. Django 1.7-alpha-1 (also reproducible on master revision 29ddae7436e8). Sample code attached.

Attachments (1)

example.tar.bz2 (3.8 KB) - added by lwarx 3 years ago.
Minimal project to reproduce the problem (run ./ test myauth)

Download all attachments as: .zip

Change History (6)

Changed 3 years ago by lwarx

Minimal project to reproduce the problem (run ./ test myauth)

comment:1 Changed 3 years ago by bmispelon

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Severity changed from Normal to Release blocker
  • Triage Stage changed from Unreviewed to Accepted


I can reproduce this issue with this simple model:

from django.db import models

from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin

class User(AbstractBaseUser, PermissionsMixin):

With this model (and changing the settings to point AUTH_USER_MODEL to it), doing the initial makemigrations works but migrate fails with the error. However, migrate will work if the migrations can be faked (for example if the table has been created using a different version of Django).
The error can always be triggered by doing ./ test <appname> (where <appname> is the name of the app containing the custom user model).

I'm marking this as a release blocker as well since things work on Django 1.6.


comment:2 Changed 3 years ago by Andrew Godwin <andrew@…>

  • Owner set to Andrew Godwin <andrew@…>
  • Resolution set to fixed
  • Status changed from new to closed

In 6758a9c0fc34dc9944895b98045d2b26c8147ea2:

Fixed #21872: Not detecting dependencies from M2M fields

comment:3 Changed 3 years ago by lwarx

  • Resolution fixed deleted
  • Status changed from closed to new

With this fix I'm still getting the same error using example project.

comment:4 Changed 3 years ago by andrewgodwin

  • Resolution set to fixed
  • Status changed from new to closed

The error is in the generated migration - you'll need to delete that and re-create it to fix.

comment:5 Changed 3 years ago by lwarx

Thanks for the fix!

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