I tried running makemigrations and after migrate and I am constantly getting this error:
ValueError: Related model 'users.UserProfile' cannot be resolved
What I was trying to do is Link a UserProfile model to Django’s own User Model:
from django.db import models
from django.contrib.auth.models import User
class UserProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
website = models.URLField(blank=True)
bio = models.CharField(max_length=250, blank=True)
full_name = models.CharField(max_length=250, blank=True)
The “Contests” model (as you can see in my installed apps below) uses the User Model as well without any errors.
My Installed apps look like this :
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'users',
'social.apps.django_app.default',
'crispy_forms',
'pages',
'contests',
]
My migration file 0001_initial.py is the following:
# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2016-12-30 15:45
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='UserProfile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('website', models.URLField(blank=True)),
('bio', models.CharField(blank=True, max_length=250)),
('full_name', models.CharField(blank=True, max_length=250)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
Other notes:
I use multiple settings files but my installed apps are all in my base setting file so this should not be the issue.
I am using Python Social Auth to create a Pipeline and create the UserProfile. (But this should not have any effect on the creation of the model in the database)
I even dropped the database and recreated it but I still get the same error.
Thanks in advance!!! :)
Advertisement
Answer
I have deleted all migration files from other apps and run makemigrations and migrate again.
Everything Works now.