Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circular dependency error #110

Open
anver opened this issue Jan 22, 2022 · 2 comments
Open

Circular dependency error #110

anver opened this issue Jan 22, 2022 · 2 comments

Comments

@anver
Copy link

anver commented Jan 22, 2022

SeederCommandError: Circular dependencies exist among these items: {'store.models.Collection':{'store.models.Product'}, 'store.models.OrderItem':{'store.models.Product'}, 'store.models.Product':{'store.models.Collection'}}

I get this circular dependency error while seeding, is there any option to fix this?

@AngelOnFira
Copy link
Collaborator

Hmm, this seems like a circular dependency error in your code. Can you share more about your project's environment?

@anver
Copy link
Author

anver commented Jan 23, 2022

Hmm, this seems like a circular dependency error in your code. Can you share more about your project's environment?

Django==4.0.1
django-seed==0.3.1
fake-factory==9999.9.9
Faker==11.3.0
idna==3.3
isort==5.10.1
Jinja2==3.0.3
jinja2-time==0.2.0
lazy-object-proxy==1.7.1
MarkupSafe==2.0.1
mccabe==0.6.1
platformdirs==2.4.1
poyo==0.5.0
psycopg2-binary==2.9.3
pycodestyle==2.8.0
pylint==2.12.2
python-dateutil==2.8.2
python-slugify==5.0.2
python-webpack-boilerplate==0.0.10
requests==2.27.1
six==1.16.0
sqlparse==0.4.2
text-unidecode==1.3
toml==0.10.2
toposort==1.7
urllib3==1.26.8
wrapt==1.13.3

python 3-alpine docker container

from django.db import models

# Create your models here.
from django.db.models import Model


class Promotions(Model):
    description = models.CharField(max_length=255)
    discount = models.FloatField()


class Collection(Model):
    title = models.CharField(max_length=255)
    featured_product = models.ForeignKey(
        'Product', on_delete=models.SET_NULL, null=True, related_name='+')


class Product(Model):
    title = models.CharField(max_length=255)
    description = models.TextField()
    slug = models.SlugField()
    price = models.DecimalField(max_digits=10, decimal_places=2)
    inventory = models.IntegerField()
    collection = models.ForeignKey(
        Collection, on_delete=models.PROTECT)
    promotions = models.ManyToManyField(Promotions)
    last_update = models.DateTimeField(auto_now=True)


class Customer(Model):
    BRONZE = 'B'
    SILVER = 'S'
    GOLD = 'G'
    MEMBESHIP_TYPES = [(BRONZE, 'Bronze'), (SILVER, 'Silver'), (GOLD, 'Gold')]
    first_name = models.CharField(max_length=255)
    last_name = models.CharField(max_length=255)
    email = models.EmailField(unique=True)
    phone = models.CharField(max_length=255)
    date_of_birth = models.DateField()
    membership = models.CharField(
        max_length=1, choices=MEMBESHIP_TYPES, default=BRONZE)


class Order(Model):
    PENDING = 'P'
    COMPLETED = 'C'
    FAILED = 'F'
    STATUSES = [(
        PENDING, 'Pending'), (COMPLETED, 'Completed'), (FAILED, 'Failed')]
    placed_at = models.DateTimeField(auto_now_add=True)
    customer = models.ForeignKey(Customer, on_delete=models.PROTECT)
    payment_status = models.CharField(
        max_length=1, choices=STATUSES, default=PENDING)


class OrderItem(Model):
    order = models.ForeignKey(Order, on_delete=models.PROTECT)
    product = models.ForeignKey(Product, on_delete=models.PROTECT)
    quantity = models.IntegerField()
    price = models.DecimalField(max_digits=10, decimal_places=2)


class Address(Model):
    street = models.CharField(max_length=255)
    address = models.CharField(max_length=255)
    city = models.CharField(max_length=255)
    customer = models.ForeignKey(Customer, on_delete=models.CASCADE)


class Cart(Model):
    created_at = models.DateTimeField(auto_now_add=True)
    customer = models.ForeignKey(Customer, on_delete=models.CASCADE)


class CartItem(Model):
    cart = models.ForeignKey(Cart, on_delete=models.CASCADE)
    product = models.ForeignKey(Product, on_delete=models.CASCADE)
    quantity = models.IntegerField()

when i disable this line the seeding works

class Collection(Model):
    title = models.CharField(max_length=255)
    # featured_product = models.ForeignKey(
    #     'Product', on_delete=models.SET_NULL, null=True, related_name='+')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants