Django 1.7.1中的django.db.migrations.graph.CircularDependencyError

时间:2014-10-29 19:31:05

标签: mysql django

刚升级到Django 1.7.1,我正在尝试设置一个全新的开发环境。我运行用户迁移确定,但是当我尝试运行推文迁移时,我得到了

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/libbyh/Documents/virtualenvs/fyl/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/Users/libbyh/Documents/virtualenvs/fyl/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/libbyh/Documents/virtualenvs/fyl/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/libbyh/Documents/virtualenvs/fyl/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/Users/libbyh/Documents/virtualenvs/fyl/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 106, in handle
    plan = executor.migration_plan(targets)
  File "/Users/libbyh/Documents/virtualenvs/fyl/lib/python2.7/site-packages/django/db/migrations/executor.py", line 49, in migration_plan
    for migration in self.loader.graph.forwards_plan(target):
  File "/Users/libbyh/Documents/virtualenvs/fyl/lib/python2.7/site-packages/django/db/migrations/graph.py", line 55, in forwards_plan
    return self.dfs(node, lambda x: self.dependencies.get(x, set()))
  File "/Users/libbyh/Documents/virtualenvs/fyl/lib/python2.7/site-packages/django/db/migrations/graph.py", line 105, in dfs
    raise CircularDependencyError()
django.db.migrations.graph.CircularDependencyError

所以我试图追踪循环依赖。以下是准备迁移的模型:

用户/ models.py

from django.db import models

# Create your models here.
class UsersTweets(models.Model):
    id = models.IntegerField(primary_key=True)
    user = models.ForeignKey('users.User')
    tweet = models.ForeignKey('tweets.Tweet')
    source = models.BooleanField() # sent the tweet
    target = models.BooleanField() # received a reply in the tweet

    class Meta:
        managed = True

class User(models.Model):
    id = models.IntegerField(primary_key=True)
    twitter_id = models.CharField(max_length=21, unique=True)
    twitter_name = models.CharField(max_length=55, unique=True)
    fullname = models.CharField(max_length=45)
    followers = models.IntegerField()
    following = models.IntegerField()
    favorites = models.IntegerField()
    tweets = models.IntegerField()
    timezone = models.CharField(max_length=45, blank=True)
    legislator = models.ForeignKey('users.Legislator', blank=True, null=True)

    class Meta:
        managed = True

class Legislator(models.Model):
    id = models.IntegerField(primary_key=True)
    PARTY = (
        ('Democrat','Democrat'),
        ('Republican','Republican'),
        ('Independent','Independent'),
    )
    GENDER = (
        ('M','Man'),
        ('F','Woman'),
    )
    TYPE = (
        ('sen','Senator'),
        ('rep','Representative')
    )
    STATE = (
        ('AK', 'Alaska'),
        ('AL', 'Alabama'),
        ('AR', 'Arkansas'),
        ('AS', 'American Samoa'),
        ('AZ', 'Arizona'),
        ('CA', 'California'),
        ('CO', 'Colorado'),
        ('CT', 'Connecticut'),
        ('DC', 'District of Columbia'),
        ('DE', 'Delaware'),
        ('FL', 'Florida'),
        ('GA', 'Georgia'),
        ('GU', 'Guam'),
        ('HI', 'Hawaii'),
        ('IA', 'Iowa'),
        ('ID', 'Idaho'),
        ('IL', 'Illinois'),
        ('IN', 'Indiana'),
        ('KS', 'Kansas'),
        ('KY', 'Kentucky'),
        ('LA', 'Louisiana'),
        ('MA', 'Massachusetts'),
        ('MD', 'Maryland'),
        ('ME', 'Maine'),
        ('MI', 'Michigan'),
        ('MN', 'Minnesota'),
        ('MO', 'Missouri'),
        ('MP', 'Northern Mariana Islands'),
        ('MS', 'Mississippi'),
        ('MT', 'Montana'),
        ('NA', 'National'),
        ('NC', 'North Carolina'),
        ('ND', 'North Dakota'),
        ('NE', 'Nebraska'),
        ('NH', 'New Hampshire'),
        ('NJ', 'New Jersey'),
        ('NM', 'New Mexico'),
        ('NV', 'Nevada'),
        ('NY', 'New York'),
        ('OH', 'Ohio'),
        ('OK', 'Oklahoma'),
        ('OR', 'Oregon'),
        ('PA', 'Pennsylvania'),
        ('PR', 'Puerto Rico'),
        ('RI', 'Rhode Island'),
        ('SC', 'South Carolina'),
        ('SD', 'South Dakota'),
        ('TN', 'Tennessee'),
        ('TX', 'Texas'),
        ('UT', 'Utah'),
        ('VA', 'Virginia'),
        ('VI', 'Virgin Islands'),
        ('VT', 'Vermont'),
        ('WA', 'Washington'),
        ('WI', 'Wisconsin'),
        ('WV', 'West Virginia'),
        ('WY', 'Wyoming'),
    )
    last_name = models.CharField(max_length=17, blank=True)
    first_name = models.CharField(max_length=11, blank=True)
    gender = models.CharField(max_length=1, blank=True)
    chamber = models.CharField(max_length=3, blank=True)
    state = models.CharField(max_length=2, blank=True)
    party = models.CharField(max_length=11, blank=True)
    url = models.CharField(max_length=36, blank=True)
    address = models.CharField(max_length=55, blank=True)
    phone = models.CharField(max_length=12, blank=True)
    contact_form = models.CharField(max_length=103, blank=True)
    rss_url = models.CharField(max_length=106, blank=True)
    facebook = models.CharField(max_length=27, blank=True)
    facebook_id = models.IntegerField(blank=True, null=True)
    youtube = models.CharField(max_length=20, blank=True)
    youtube_id = models.IntegerField(blank=True, null=True)
    bioguide_id = models.IntegerField(blank=True, null=True)
    thomas_id = models.IntegerField(blank=True, null=True)
    opensecrets_id = models.IntegerField(blank=True, null=True)
    lis_id = models.IntegerField(blank=True, null=True)
    cspan_id = models.IntegerField(blank=True, null=True)
    govtrack_id = models.IntegerField(blank=True, null=True)
    votesmart_id = models.IntegerField(blank=True, null=True)
    ballotpedia_id = models.IntegerField(blank=True, null=True)
    washington_post_id = models.IntegerField(blank=True, null=True)
    icpsr_id = models.IntegerField(blank=True, null=True)
    wikipedia_id = models.CharField(max_length=40, blank=True)

    def _get_name_with_honor(self):
        return '%s. %s %s (%s-%s)' % ((self.chamber).title(), self.first_name, self.last_name, self.party[:1], self.state)
    honor_name = property(_get_name_with_honor) 

    def __unicode__(self):
        return self.last_name

    class Meta:
        managed = True

鸣叫/ models.py

from django.db import models

# Create your models here.
class Tweet(models.Model):
    tweet_id = models.CharField(primary_key=True, max_length=21)
    created_at = models.DateTimeField()
    text = models.CharField(max_length=255)
    source = models.CharField(max_length=255, blank=True)
    location_geo = models.TextField(blank=True) # This field type is a guess.
    location_geo_0 = models.DecimalField(max_digits=14, decimal_places=10, blank=True, null=True)
    location_geo_1 = models.DecimalField(max_digits=14, decimal_places=10, blank=True, null=True)
    iso_language = models.CharField(max_length=3)
    user = models.ManyToManyField('users.User', through = "users.UsersTweets")
    class Meta:
        managed = True

我检查了another StackOverflow question about this error,但是我没有从错误中获得有关依赖关系可能位置的任何信息。试图关注this advice,但不确定如何编辑swappable_dependency。有任何想法吗?谢谢!

1 个答案:

答案 0 :(得分:1)

cd /var
sudo mkdir mysql
sudo chmod 755 mysql
cd mysql
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock mysql.sock