ImportError: cannot import name 'RightsMaster' from partially initialized module 'DATABASE.models' (most likely due to a circular import)
from DATABASE.models import ModuleMaster, PageMaster, RightsMaster ImportError: cannot import name 'RightsMaster' from partially initialized module 'DATABASE.models' (most likely due to a circular import) (C:\Users\ADMIN\Desktop\python server\DATABASE\models_init_.py)
module_page.py
from django.db import models
class ModuleMaster(models.Model):
active = models.BooleanField(default=True)
id = models.BigAutoField(primary_key=True)
name = models.CharField(max_length=80)
icon_class = models.CharField(max_length=100)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.name
class Meta:
managed = False
db_table = 'module_master'
class PageMaster(models.Model):
id = models.BigAutoField(primary_key=True)
active = models.BooleanField(default=True)
module = models.ForeignKey(ModuleMaster, models.DO_NOTHING)
name = models.CharField(max_length=80)
path = models.CharField(max_length=255)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.name
class Meta:
managed = False
db_table = 'page_master'
rights_master.py
from django.db import models
class RightsMaster(models.Model):
full_name = models.CharField(max_length=30, default='', blank=True, null=True)
short_name = models.CharField(max_length=4, default='')
description = models.CharField(max_length=80, default='', blank=True, null=True)
active = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
db_table = 'rights_master'
user_rights.py
from django.db import models
from DATABASE.models import ModuleMaster, PageMaster, RightsMaster
class UserRights(models.Model):
user = models.CharField(max_length=30)
right = models.ForeignKey(RightsMaster, models.CASCADE)
module = models.ForeignKey(ModuleMaster, models.CASCADE)
page = models.ForeignKey(PageMaster, models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
db_table = 'user_rights'
init.py
from .profocus_py.module_page import ModuleMaster, PageMaster
from .profocus_py.user_rights import UserRights
from .profocus_py.rights_master import RightsMaster
I fixed it
I was trying to import ModuleMaster in user_rights.py But it is already connected with Foreign_key in PageMaster