Django AbstractUser migration error cannot be resolved

I want to add a Django User field. So I check this doc: https://docs.djangoproject.com/en/1.8/topics/auth/customizing/

I decide to use AbstractUser

to solve my problem.

Add to

class MyUser(AbstractUser): 
    nickname = models.CharField(max_length=64, blank=False)

      

before muse.models

.

and add AUTH_USER_MODEL = "muse.MyUser"

to the file settings.py

.

But when I migrate

always have errors:

  Synchronize unmigrated apps: staticfiles, messages
  Apply all migrations: admin, contenttypes, muse, auth, sessions
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
  Installing custom SQL...
Running migrations:
  Rendering model states... DONE
  Applying admin.0001_initial...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 441, in execute
    output = self.handle(*args, **options)
  File "/Library/Python/2.7/site-packages/django/core/management/commands/migrate.py", line 221, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/Library/Python/2.7/site-packages/django/db/migrations/executor.py", line 110, in migrate
    self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
  File "/Library/Python/2.7/site-packages/django/db/migrations/executor.py", line 147, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Library/Python/2.7/site-packages/django/db/migrations/migration.py", line 115, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/Library/Python/2.7/site-packages/django/db/migrations/operations/models.py", line 59, in database_forwards
    schema_editor.create_model(model)
  File "/Library/Python/2.7/site-packages/django/db/backends/base/schema.py", line 232, in create_model
    definition, extra_params = self.column_sql(model, field)
  File "/Library/Python/2.7/site-packages/django/db/backends/base/schema.py", line 131, in column_sql
    db_params = field.db_parameters(connection=self.connection)
  File "/Library/Python/2.7/site-packages/django/db/models/fields/related.py", line 1989, in db_parameters
    return {"type": self.db_type(connection), "check": []}
  File "/Library/Python/2.7/site-packages/django/db/models/fields/related.py", line 1980, in db_type
    rel_field = self.related_field
  File "/Library/Python/2.7/site-packages/django/db/models/fields/related.py", line 1886, in related_field
    return self.foreign_related_fields[0]
  File "/Library/Python/2.7/site-packages/django/db/models/fields/related.py", line 1620, in foreign_related_fields
    return tuple(rhs_field for lhs_field, rhs_field in self.related_fields)
  File "/Library/Python/2.7/site-packages/django/db/models/fields/related.py", line 1607, in related_fields
    self._related_fields = self.resolve_related_fields()
  File "/Library/Python/2.7/site-packages/django/db/models/fields/related.py", line 1592, in resolve_related_fields
    raise ValueError('Related model %r cannot be resolved' % self.rel.to)
ValueError: Related model 'muse.MyUser' cannot be resolved

      

What's wrong?

+3


source to share


1 answer


In my case, there was a tricky workaround available, and I am not suggesting it because my case was so special. I had my own database management and explained why Django built the query for reasons (it was a university project and it was prohibited). I was manually manipulating the database structure and had my own user model and authentication.

The workaround was to create a migration and then manually delete your operations. After creating the migration, I had to disable AUTH_USER_MODEL

, migrate and then enable the setting to get the authentication system working.



Hope this was helpful.

0


source







All Articles