0

I am writing my first Django project and using Django 1.7, and for my login and authentication I am using the Django User model. I am now creating my models. Project and User share a Many-to-Many relationship

models.py:

from django.db import models

from django import forms

from django.contrib.auth.models import User

class Project(models.Model):
    project_name = models.CharField(max_length=128, unique = True)
    project_description = models.CharField(max_length=128)
    users_annotating = models.ManyToManyField(User)

However, I get this error when I try to migrate:

ValueError: Related model 'auth.User' cannot be resolved

Does anyone understand this problem?

waterAddict
  • 1
  • 1
  • 2

1 Answers1

3

I'm guessing that you have

dependencies = [
    migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

in your newly created Django 1.7 migration.

If you comment out that dependency and just in case replace it with

dependencies = [
    ('auth', '__first__'),
]

things should work.

mislavcimpersak
  • 2,880
  • 1
  • 27
  • 30
  • Thanks! I ended up deleting all my migrations and everything worked! – waterAddict Mar 23 '14 at 16:18
  • @waterAddict Glad to help. Do you need any more help with this question? If this answer solved your problem please mark it as accepted by clicking the check mark next to the answer. – mislavcimpersak Mar 24 '14 at 09:48
  • Any chance you could explain why this fixes the problem? – Collin Apr 18 '14 at 20:40
  • @Collin There were issues with `swappable_dependency` in django 1.7 alpha. I don't know if things are fixed now. It is explained [here](https://code.djangoproject.com/ticket/22325). Basically: _"the issue is that swappable_dependency resolves to app_label.first, which doesn't make a lot of sense when the app with the migrations is itself being migrated"_ – mislavcimpersak Apr 22 '14 at 09:32