Django Migration Error - django

After importing Psycopg2==2.7.4 into my server, I can no longer run my server properly. After adding new fields, this is what happens now in my terminal whenever I try to make migrate after makemigrations(python manage.py migrate):
Apply all migrations: admin, auth, buddysapp, contenttypes, oauth2_provider, sessions, social_django
Running migrations:
Applying buddysapp.0038_auto_20180321_0025...Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/core/management/base.py", line 305, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/core/management/base.py", line 356, in execute
output = self.handle(*args, **options)
File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 202, in handle
targets, plan, fake=fake, fake_initial=fake_initial
File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/db/migrations/executor.py", line 97, in migrate
state = self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/db/migrations/executor.py", line 132, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/db/migrations/executor.py", line 237, in apply_migration
state = migration.apply(state, schema_editor)
File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 84, in database_forwards
field,
File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/db/backends/sqlite3/schema.py", line 231, in add_field
self._remake_table(model, create_fields=[field])
File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/db/backends/sqlite3/schema.py", line 113, in _remake_table
self.effective_default(field)
File "/Users/hsi/Desktop/myvirtualenv/buddys/lib/python3.6/site-packages/django/db/backends/sqlite3/schema.py", line 68, in quote_value
raise ValueError("Cannot quote parameter value %r of type %s" % (value, type(value)))
ValueError: Cannot quote parameter value <psycopg2._json.Json object at 0x10ea5e748> of type <class 'psycopg2._json.Json'>
Any ideas, let me know.
Update: Migration file 0038
rom __future__ import unicode_literals
import buddysapp.models
import django.contrib.postgres.fields.jsonb
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('buddysapp', '0037_auto_20180318_1816'),
]
operations = [
migrations.AddField(
model_name='dispensary',
name='businessHours',
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=buddysapp.models.business_hours_default, null=True),
),
migrations.AlterField(
model_name='order',
name='status',
field=models.IntegerField(choices=[(1, 'Your Order Is Being Picked Right Off The Plant!'), (2, 'Picked, Weighed, And Ready For Delivery.'), (3, 'The Best Bud Is Heading Straight To Your Door.'), (4, 'Delivered'), (0, 'Canceled/Refunded')]),
),
]

You can’t use a JSONField from django.contrib.postgres with an Sqlite3 database.
You need to either set up a PostgreSQL database and update your DATABASES setting, or use a different field in your model.

Related

Django renaming class casued AttributeError: 'str' object has no attribute '_meta'

How can I solve this issue, I renamed a through Model class and now getting the following error when trying to migrate:
(django_env) UKC02TQH6UHV22:pcc_django rki23$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, microblog, project_portal, sessions, url_tree
Running migrations:
Applying project_portal.0012_auto_20200205_1241...Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/Users/rki23/opt/anaconda3/envs/django_env/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/Users/rki23/opt/anaconda3/envs/django_env/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/rki23/opt/anaconda3/envs/django_env/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/rki23/opt/anaconda3/envs/django_env/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/Users/rki23/opt/anaconda3/envs/django_env/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/Users/rki23/opt/anaconda3/envs/django_env/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 234, in handle
fake_initial=fake_initial,
File "/Users/rki23/opt/anaconda3/envs/django_env/lib/python3.7/site-packages/django/db/migrations/executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/Users/rki23/opt/anaconda3/envs/django_env/lib/python3.7/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/Users/rki23/opt/anaconda3/envs/django_env/lib/python3.7/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "/Users/rki23/opt/anaconda3/envs/django_env/lib/python3.7/site-packages/django/db/migrations/migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/Users/rki23/opt/anaconda3/envs/django_env/lib/python3.7/site-packages/django/db/migrations/operations/fields.py", line 249, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/Users/rki23/opt/anaconda3/envs/django_env/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 524, in alter_field
not new_field.remote_field.through._meta.auto_created):
AttributeError: 'str' object has no attribute '_meta'
(django_env) UKC02TQH6UHV22:pcc_django rki23$
What do I need to do to fix this please?
THis is the migration file that is causing the issue. The name change was for a many to many field.
# Generated by Django 2.2.5 on 2020-02-05 12:41
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('project_portal', '0011_auto_20200127_0953'),
]
operations = [
migrations.RenameModel(
old_name='CategorySatisfied',
new_name='TaskComplete',
),
migrations.AlterField(
model_name='updatecategory',
name='projects',
field=models.ManyToManyField(blank=True, related_name='task_complete', through='project_portal.CategorySatisfied', to='project_portal.Project'),
),
]

Django database and migration error, ValueError: Related model 'Users.user' cannot be resolved

I am facing a very very strange situation with my Django (in general). I'm using Django 2.2 and Python 3.6.7.
Every single time I create a new project, using:
django-admin startproject myproject
and trying to migrate it, I got this error :
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying admin.0004_auto_20190630_1438... OK
Applying admin.0005_auto_20190630_1441...Traceback (most recent call last):
File "C:\Dev\Django\myproject\manage.py", line 21, in <module>
main()
File "C:\Dev\Django\myproject\manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Dev\Django\Env\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Dev\Django\Env\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Dev\Django\Env\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Dev\Django\Env\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Dev\Django\Env\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Dev\Django\Env\lib\site-packages\django\core\management\commands\migrate.py", line 234,
in handle
fake_initial=fake_initial,
File "C:\Dev\Django\Env\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake,
fake_initial=fake_initial)
File "C:\Dev\Django\Env\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Dev\Django\Env\lib\site-packages\django\db\migrations\executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Dev\Django\Env\lib\site-packages\django\db\migrations\migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Dev\Django\Env\lib\site-packages\django\db\migrations\operations\fields.py", line 249, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "C:\Dev\Django\Env\lib\site-packages\django\db\backends\sqlite3\schema.py", line 137, in alter_field
super().alter_field(model, old_field, new_field, strict=strict)
File "C:\Dev\Django\Env\lib\site-packages\django\db\backends\base\schema.py", line 507, in alter_field
new_db_params = new_field.db_parameters(connection=self.connection)
File "C:\Dev\Django\Env\lib\site-packages\django\db\models\fields\related.py", line 966, in db_parameters
return {"type": self.db_type(connection), "check": self.db_check(connection)}
File "C:\Dev\Django\Env\lib\site-packages\django\db\models\fields\related.py", line 963, in db_type
return self.target_field.rel_db_type(connection=connection)
File "C:\Dev\Django\Env\lib\site-packages\django\db\models\fields\related.py", line 878, in target_field
return self.foreign_related_fields[0]
File "C:\Dev\Django\Env\lib\site-packages\django\db\models\fields\related.py", line 632, in foreign_related_fields
return tuple(rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field)
File "C:\Dev\Django\Env\lib\site-packages\django\db\models\fields\related.py", line 619, in related_fields
self._related_fields = self.resolve_related_fields()
File "C:\Dev\Django\Env\lib\site-packages\django\db\models\fields\related.py", line 604, in resolve_related_fields
raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
ValueError: Related model 'Users.user' cannot be resolved
this occurs everytime I try to migrate all my projects, even all old projects.
Is this some kind of django bug? or did I configure it improperly? I also use the default django settings (without even touching anything).
I messed up by this error. I cannot do any migrations to all my projects.
I have uninstalled django and reinstalled it back, but nothing changed, I got the same error.
A few moments ago I created a custom user model (AbstractBaseUser) in my project. And it was running perfectly. But I when I try to input data to any model in the admin panel, I got error FOREIGN KEY constraint failed (whereas I had only one model, AbstractBaseUser model). I didn't know what to do with that, And I deleted that project.
Afterwards, I created a new project (for learning purposes), and trying migrate it, this critical serious error appeared.
Do guys have any solution to overcome this? Please help me out of this problem

Upgrade Django project to Python3 - migrations fail

I have a Django project which has been developed with Python2.7, it is currently using Django version 1.10. I am now in the process of upgrading - first to Python3, and then afterwards I will do the Django upgrade.
When I make Python3 virtual environment and run the tests:
venv bash% ./manage.py tests
I get a massive traceback:
Traceback (most recent call last):
File "./manage.py", line 9, in <module>
execute_from_command_line( sys.argv )
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/commands/test.py", line 29, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/base.py", line 305, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/base.py", line 356, in execute
output = self.handle(*args, **options)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/commands/test.py", line 72, in handle
failures = test_runner.run_tests(test_labels)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/test/runner.py", line 549, in run_tests
old_config = self.setup_databases()
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/test/runner.py", line 499, in setup_databases
self.parallel, **kwargs
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/test/runner.py", line 743, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/backends/base/creation.py", line 70, in create_test_db
run_syncdb=True,
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 130, in call_command
return command.execute(*args, **defaults)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/base.py", line 356, in execute
output = self.handle(*args, **options)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 202, in handle
targets, plan, fake=fake, fake_initial=fake_initial
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/migrations/executor.py", line 97, in migrate
state = self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/migrations/executor.py", line 132, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/migrations/executor.py", line 237, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/migrations/operations/models.py", line 96, in database_forwards
schema_editor.create_model(model)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 271, in create_model
self.quote_name(field.column),
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 115, in quote_name
return self.connection.ops.quote_name(name)
File "/home/hove/sleipner/venv/lib/python3.5/site-packages/django/db/backends/sqlite3/operations.py", line 153, in quote_name
if name.startswith('"') and name.endswith('"'):
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
As I understand it the problem is unicode/string issues in the migrations? I have tried to follow the advice: "Add from __future__ import unicode_literals at the top every module". The resulting code still works nicely in Python2.7, but manage.py test fails in the same way for Python3.
For all it is worth the project seems to "basically" work in Python3 when I do:
bash% manage.py runserver
Update:
These are my database settings - might very well be something wrong with this, but observe that it has worked in Python2.7 for many years - and still does:
if "test" in sys.argv:
DATABASES = { 'default' : {
"ENGINE" : "django.db.backends.sqlite3",
"NAME" : "friskby.sqlite",
"TEST" : {
"NAME" : "friskby-test.sqlite"}}}
else:
DATABASE_URL = os.environ.get("DATABASE_URL")
if DATABASE_URL:
config = dj_database_url.config(default = DATABASE_URL)
DATABASES = { 'default': config }
else:
raise Exception("The DATABASE_URL environment variable has not bee set")
The comment from #Will Keeling set me on the right track. My migrations (originally created with Python2.7) had many:
... db_column = b"NAME_OF_COLUMN", ...
statements. I just removed all the leading b - and lo and behold all tests pass in both Python2.7 and Python3.

Django migrate command fails with change in foreign key related name

I have a model with a foreign key field. I want to give the foreign key a related name. However, migration fails because of the following error:
IndexError: list index out of range
I'm using Django==1.10.5
Database backend is PostgreSQL
models.py Before/After migrations
Before:
class Contest_participants(models.Model):
contest = models.ForeignKey(Contest)
After:
class Contest_participants(models.Model):
contest = models.ForeignKey(Contest, related_name='contests')
The makemigrations command works fine, but the migrate command fails with the above noted error.
Complete Traceback Error:
Running migrations:
Applying teams.0013_auto_20171031_1225...Traceback (most recent call last):
File "manage.py", line 19, in <module>
execute_from_command_line(sys.argv)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/db/migrations/executor.py", line 115, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/db/migrations/operations/fields.py", line 204, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 495, in alter_field
old_db_params, new_db_params, strict)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/db/backends/postgresql/schema.py", line 117, in _alter_field
new_db_params, strict,
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 504, in _alter_field
fk_names = self._constraint_names(model, [old_field.column], foreign_key=True)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 931, in _constraint_names
constraints = self.connection.introspection.get_constraints(cursor, model._meta.db_table)
File "/home/aps/Documents/neuron/venv/lib/python3.5/site-packages/django/db/backends/postgresql/introspection.py", line 178, in get_constraints
"foreign_key": tuple(used_cols[0].split(".", 1)) if kind.lower() == "foreign key" else None,
IndexError: list index out of range
EDIT: Migrations
class Migration(migrations.Migration):
dependencies = [
('teams', '0012_auto_20170904_1524'),
]
operations = [
migrations.AlterField(
model_name='contest_participants',
name='contest',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='contests', to='contest.Contest'),
),
]

Django AbstractUser migrate cannot be resolved

I want add a field Django User. So I check this document: https://docs.djangoproject.com/en/1.8/topics/auth/customizing/
I decide use AbstractUser to solve my problem.
Add:
class MyUser(AbstractUser):
nickname = models.CharField(max_length=64, blank=False)
to muse.models.
and add AUTH_USER_MODEL = "muse.MyUser" to the settings.py file.
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 ?
In my case a tricky workaround was available and I don't suggest it because my case was so special. I had my own database management and was putting Django query builder aside for reasons (It was a university project and it was not allowed). I manipulated my database structure manually and had my own user model and authentication back-end.
The workaround was to create migrations and then to remove their operations manually. After creating migrations I had to disable AUTH_USER_MODEL, migrate and then enable the setting to make the authentication system work.
Hope it was helpful.