python - Circular Dependency Error in Django -


having issue when running makemigrations/migrate django project.

getting error:

traceback (most recent call last):   file "manage.py", line 10, in <module>     execute_from_command_line(sys.argv)   file "c:\users\crstu\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line     utility.execute()   file "c:\users\crstu\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\__init__.py", line 345, in execute     self.fetch_command(subcommand).run_from_argv(self.argv)   file "c:\users\crstu\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv     self.execute(*args, **cmd_options)   file "c:\users\crstu\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\base.py", line 399, in execute     output = self.handle(*args, **options)   file "c:\users\crstu\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\commands\migrate.py", line 139, in handle     plan = executor.migration_plan(targets)   file "c:\users\crstu\appdata\local\programs\python\python36-32\lib\site-packages\django\db\migrations\executor.py", line 60, in migration_plan     migration in self.loader.graph.forwards_plan(target):   file "c:\users\crstu\appdata\local\programs\python\python36-32\lib\site-packages\django\db\migrations\graph.py", line 149, in forwards_plan     self.ensure_not_cyclic(target, lambda x: (parent.key parent in self.node_map[x].parents))   file "c:\users\crstu\appdata\local\programs\python\python36-32\lib\site-packages\django\db\migrations\graph.py", line 241, in ensure_not_cyclic     raise circulardependencyerror(", ".join("%s.%s" % n n in cycle)) django.db.migrations.exceptions.circulardependencyerror: accounts.0001_initial, projects.0001_initial 

i have 2 apps---one called accounts , called projects

for accounts app, here model:

from django.contrib.auth.models import (     abstractbaseuser,     baseusermanager,     permissionsmixin ) django.db import models django.utils import timezone django.conf import settings django.db.models.signals import post_save import os  projects.models import skill, project   def avatar_upload_path(instance, filename):     return os.path.join('avatars', 'user_{0}', '{1}').format(         instance.user.id, filename)  class usermanager(baseusermanager):     def create_user(self, email, username=none, password=none):         if not email:             raise valueerror("users must have email address")          if not username:             username = email.split('@')[0]          user = self.model(             email=self.normalize_email(email),             username=username,         )         user.set_password(password)         user.save()         return user      def create_superuser(self, email, username, password):         user = self.create_user(             email,             username,             password,         )         user.is_staff = true         user.is_superuser = true         user.save()         return user   class user(abstractbaseuser, permissionsmixin):     email = models.emailfield(unique=true)     username = models.charfield(max_length=40, unique=true, default='')     date_joined = models.datetimefield(default=timezone.now)     is_active = models.booleanfield(default=true)     is_staff = models.booleanfield(default=false)      objects = usermanager()      username_field = 'email'     required_fields = ['username']      def __str__(self):         return "@{}".format(self.username)      def get_short_name(self):         return self.username      def get_long_name(self):         return "@{} ({})".format(self.username, self.email)   class userprofile(models.model):     user = models.onetoonefield(settings.auth_user_model)     first_name = models.charfield(max_length=40, default='', blank=true)     last_name = models.charfield(max_length=40, default='', blank=true)     bio = models.textfield(blank=true, default='')     avatar = models.imagefield('avatar picture',                                upload_to=avatar_upload_path,                                null=true,                                blank=true)     skills = models.manytomanyfield(skill)      def __str__(self):         return self.user.username      @property     def get_avatar_url(self):         if self.avatar:             return '/media/{}'.format(self.avatar)         return 'http://www.gravatar.com/avatar/{}?s=128&d=identicon'.format(             '94d093eda664addd6e450d7e9881bcad'         )   def create_profile(sender, **kwargs):     if kwargs['created']:         user_profile = userprofile.objects.create(user=kwargs['instance'])  post_save.connect(create_profile, sender=user) 

and projects app here model. thought maybe since using many many field userprofile skill class in app maybe issue...so tried run makemigrations separately on 2 apps---while commenting out 'skill' userprofile. didn't work. not sure now.

from django.conf import settings django.db import models  django.core.urlresolvers import reverse  class skill(models.model):     """user skills class."""     android = 1     designer = 2     java = 3     php = 4     python = 5     rails = 6     wordpress = 7     ios = 8      skill_choices = (         (str(android), 'android developer'),         (str(designer), 'designer'),         (str(java), 'java developer'),         (str(php), 'php developer'),         (str(python), 'python developer'),         (str(rails), 'rails developer'),         (str(wordpress), 'wordpress developer'),         (str(ios), 'ios developer')     )      name = models.charfield(max_length=140, choices=skill_choices, default='unknown')      def __str__(self):         return self.get_name_display()   class project(models.model):     owner = models.foreignkey(settings.auth_user_model, related_name='project', null=true)     created_at = models.datetimefield(auto_now_add=true)     title = models.charfield(max_length=255)     description = models.textfield()     requirements = models.textfield(default='')     timeline = models.charfield(max_length=255, blank=true)     complete = models.booleanfield(default=false)      @property     def open_positions(self):         return self.positions.exclude(filled=true)      def __str__(self):         return self.title.title()      def get_absolute_url(self):         return reverse("projects:project_detail", kwargs={"pk": self.pk})   class position(models.model):     project = models.foreignkey(project, default='',related_name='positions')     name = models.charfield(max_length=140)     description = models.textfield()     skill = models.foreignkey(skill, default='', null=true)     filled = models.booleanfield(default=false)      def __str__(self):         return '{} - {}'.format(self.project.title.title(), self.name.title()) 

your 2 migrations have dependency on each other. @ generated migration account app , see this

class migration(migrations.migration):      dependencies = [         ('projects', '0001_initial'),     ] 

there similar in projects migration

you need delete these 2 migration files , run makemigrations again without specifying app name


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -