0

So here is my problem. I got three django apps. paper,feeds,activity. Activity has model defined as:

from django.db import models
from django.contrib.auth.models import User
from django.db.models import Q


class Tag(models.Model):
    name = models.CharField(max_length=20)


class Bookmark(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    feed = models.ForeignKey(
        "feeds.Feeds", blank=True, null=True, on_delete=models.CASCADE)
    paper = models.ForeignKey(
        "paper.Paper", blank=True, null=True, on_delete=models.CASCADE)

    class Meta:
        constraints = [
            models.CheckConstraint(
                check=~Q(feed=None) | ~Q(paper=None),
                name='at_least_1_non_null_bookmark'),
            models.CheckConstraint(
                check=Q(feed=None) | Q(paper=None),
                name='at_least_1_null_bookmark'),
        ]


class Comment(models.Model):
    AUDIO = "AUDIO"
    VIDEO = "VIDEO"
    TEXT = "TEXT"
    EXPLAIN = "EXPLAIN"

    MEDIA_CHOICES = [
        (AUDIO, "AUDIO"),
        (VIDEO, "VIDEO"),
        (TEXT, "TEXT"),
        (EXPLAIN, "EXPLAIN"),
    ]

    user = models.ForeignKey(User, on_delete=models.CASCADE)
    published_at = models.DateTimeField(auto_now=True)
    comment_comment = models.ForeignKey(
        "self", null=True, blank=True, on_delete=models.CASCADE
    )
    text = models.CharField(max_length=1000)
    type = models.CharField(max_length=7, choices=MEDIA_CHOICES)

    feed = models.ForeignKey(
        "feeds.Feeds", blank=True, null=True, on_delete=models.CASCADE)
    paper = models.ForeignKey(
        "paper.Paper", blank=True, null=True, on_delete=models.CASCADE)

    class Meta:
        constraints = [
            models.CheckConstraint(
                check=~Q(feed=None) | ~Q(paper=None),
                name='at_least_1_non_null_paper'),
            models.CheckConstraint(
                check=Q(feed=None) | Q(paper=None),
                name='at_least_1_null_paper'),
        ]


class Vote(models.Model):
    up = "U"
    down = "D"
    VOTE_CHOICES = [
        (up, "Up"),
        (down, "Down"),
    ]

    user = models.ForeignKey(User, on_delete=models.CASCADE)
    vote_type = models.CharField(max_length=1, choices=VOTE_CHOICES)
    comment = models.ForeignKey(Comment, on_delete=models.CASCADE)

Paper has following model.

from django.db import models
from django.contrib.auth.models import User
from activity.models import Tag


class Paper(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    published_at = models.DateTimeField(auto_now=True)
    title = models.CharField(max_length=200)
    tag = models.ManyToManyField("activity.Tag")

& feeds has following model.

from django.db import models
from django.contrib.auth.models import User


class Feeds(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    published_at = models.DateTimeField(auto_now=True)
    text = models.CharField(max_length=1000)
    tag = models.ManyToManyField("activity.Tag")

While running makemigrations it is giving me error of django.db.migrations.exceptions.CircularDependencyError: paper.0001_initial, activity.0001_initial

The migration of activity is

class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('paper', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('feeds', '0001_initial'),
    ]

Any ways to solve this issue? I am not that experienced with database and stuffs. Any help would be highly appreciated. Better if it has explanation to the answer too. :p

JustABeginner
  • 785
  • 2
  • 11
  • 26

0 Answers0