[Answered ]-Django import error when trying to migrate models from app to app

1👍

You try to make cross importing. That is not allowed. Comment out the line 13 in "C:\Users\I812624\dev\mrp\src\item\models.py" if you don’t need it.

or comment out the line 3 and 4 in:

"C:\Users\I812624\dev\mrp\src\product\models.py"

and do:

itemgroup = models.ForeignKey("item.ItemGroup", on_delete=models.PROTECT)
material = models.ForeignKey("item.Material", on_delete=models.PROTECT)
👤trantu

1👍

I’m kind of guessing here that you have circular imports going on. Something in item.models is trying to import something from product.models, which is trying to import something in item.models

The solution to that is avoid it entirely by allowing Django to handle the circular relationship instead of Python, like in the answer to this question.

So in your case, remove the import here and instead reference it like a string:

@with_author  
class ItemGroup(models.Model):
    # ...
    subcategory = models.ForeignKey('product.SubCategory', on_delete=models.PROTECT)
    # ...

Leave a comment