According to the documentation, the ready() method of AppConfig is called when the registry is full, which means that models are also loaded, so references to models should not be a problem.
This line of code is still invalid because it is in ready() , though, as stated in the documentation:
You cannot import models into modules that define the application of configuration classes, but you can use get_model () to access the model class by name
Therefore, remove User._meta.get_field_by_name('email')[0]._unique=True from models.py and follow these steps in the application configuration:
class AccountsConfig(AppConfig): name = 'modules.accounts' def ready(self): self.get_model('User')._meta.get_field_by_name('email')[0]._unique=True
source share