When I python3 manage.py makemigrations
, I get bellow error:
...
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/db/models/fields/related.py", line 348, in contribute_to_class
lazy_related_operation(resolve_related_class, cls, self.remote_field.model, field=self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/db/models/fields/related.py", line 85, in lazy_related_operation
return apps.lazy_model_operation(partial(function, **kwargs), *model_keys)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/db/models/fields/related.py", line 83, in <genexpr>
model_keys = (make_model_tuple(m) for m in models)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/db/models/utils.py", line 23, in make_model_tuple
"must be of the form 'app_label.ModelName'." % model
ValueError: Invalid model reference 'x.qiyun_admin_productconfig_cloudserver.HostType
But, my HostType model path is this :
x.qiyun_admin_productconfig_cloudserver.models.HostType
.
The traceback less the .models
in it. I don't know why.
Please PAY ATTENTION, the serializer and views(serializer view) is under the api
directory.
and the settings:
...
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PARENT_DIR = os.path.abspath(os.path.join(BASE_DIR, os.pardir))
sys.path.insert(0, BASE_DIR)
sys.path.insert(0, os.path.join(PARENT_DIR,'x'))
sys.path.insert(0, os.path.join(PARENT_DIR,'x'))
sys.path.insert(0, os.path.join(PARENT_DIR,'x'))
...
INSTALLED_APPS = [
'django.contrib.admin',
....
'x.qiyun_admin_useradminmanage', #
'x.qiyun_admin_usergroups', #
'x.qiyun_admin_productconfig_common', #
'x.qiyun_admin_productconfig_cloudserver', #
'x.qiyun_admin_financialmanage_ordermanage', #
'x.qiyun_admin_financialmanage_financialmanage',
EDIT
I have two Models(AvailableArea, AddressRegion) in the same models.py(x.qiyun_admin_productconfig_cloudserver.
) :
class AvailableArea(models.Model):
name = models.CharField(max_length=8)
addressregion = models.ForeignKey(AddressRegion, default=1, related_name='availableareas', on_delete=models.CASCADE)
def __str__(self):
return self.name
def __unicode__(self):
return self.name
class AddressRegion(models.Model):
name = models.CharField(max_length=8)
def __str__(self):
return self.name
def __unicode__(self):
return self.name
You see, should I still specified the addressregion = models.ForeignKey('qiyun_admin_productconfig_cloudserver.AddressRegion',...)
?
And if other models if have ForeignKey refers to AddressRegion
, I also imported it.