I am getting the "standard" CircularDependencyError (Django 1.7c2 with 
migrations) with ManyToManyFields and a custom user.

from django.db import models
from member.models import Member
from company.models import Company

class Affiliation( models.Model ):
    member = models.ForeignKey( Member )
    company = models.ForeignKey( Company )

-- 

from django.db import models

class Company( models.Model ):
        name = models.CharField(max_length=100)

        members = models.ManyToManyField( 'member.Member', 
through='affiliation.Affiliation' )
 
-- 

class Member( AbstractBaseUser, PermissionsMixin ):
    username = models.CharField(max_length=100, unique=True)
    first_name = models.CharField(max_length=100)
    last_name = models.CharField(max_length=100)

    companies = models.ManyToManyField( 'company.Company', 
through='affiliation.Affiliation')

    is_active = models.BooleanField( default=True )
    is_staff = models.BooleanField( default=False )

    USERNAME_FIELD = 'username'
    REQUIRED_FIELDS = ['email', 'first_name', 'last_name']

    objects = MemberManager()
   
When I run makemigrations it *appears* to be putting the m2m in the second 
run of the migration:

$  python manage.py makemigrations member company
Migrations for 'member':
  0001_initial.py:
    - Create model Member
Migrations for 'affiliation':
  0001_initial.py:
    - Create model Affiliation
  0002_auto_20140816_1407.py:
    - Add field company to affiliation
    - Add field member to affiliation
Migrations for 'company':
  0001_initial.py:
    - Create model Company

According to Django this needs to be done manually but it appears to have 
been done automatically.


*In addition, you may run into a CircularDependencyError when running your 
migrations as Django won’t be able to automatically break the dependency 
loop due to the dynamic dependency. If you see this error, you should break 
the loop by moving the models depended on by your User model into a second 
migration (you can try making two normal models that have a ForeignKey to 
each other and seeing how makemigrations resolves that circular dependency 
if you want to see how it’s usually done)*
But I am still getting the error:

django.db.migrations.graph.CircularDependencyError: [('affiliation', 
u'0002_auto_20140816_1400'), (u'company', u'0001_initial'), ('member', 
u'0001_initial'), (u'affiliation', u'0002_auto_20140816_1400')]

I am very confused how I am supposed to break the loop.  There are several 
things on Google about this but it is not clear to me of the correct 
practice in 1.7(c2).

So, any help or ideas on this would be gratefully appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dc7b42df-f2f7-495e-8dff-e7cf14dfb3c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to