Reputation: 581
Just upgraded to Django 1.7.1 and am trying to setup a fresh dev environment. I ran a users migration OK, but when I try to run a tweets migration, I get
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
So I'm trying to track down the circular dependency. Here are the models ready to migrate:
users/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
tweets/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
I checked another StackOverflow question about this error, but I don't get any info from my error about where the dependency might be. Tried to follow this advice but wasn't sure how to edit the swappable_dependency
. Any ideas? Thanks!
Upvotes: 0
Views: 734
Reputation: 5084
1. In tweets/models.py comment #user = models.ManyToManyField('users.User', through = "users.UsersTweets")
2. makemigrations tweets
3. makemigrations users
4. UNcomment in tweets/models.py user = models.ManyToManyField('users.User', through = "users.UsersTweets")
5. makemigrations tweets
6. migrate
Upvotes: 1