Django 1.7 冲突模型 [英] Django 1.7 conflicting models

查看:31
本文介绍了Django 1.7 冲突模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将我的应用程序安装在project/apps/myapp"文件夹中.应用程序和 myapp 文件夹都有 init.py 文件(如果没有它们,就会出现模块丢失错误).现在我有错误:

I install my application in "project/apps/myapp" folder. Both apps and myapp folders have init.py files(Without any of them there is module missing error). Now I've the error:

Exception Type: RuntimeError at /
    Exception Value: Conflicting 'person' models in application 'resume': <class
 'apps.resume.models.Person'> and <class 'resume.models.Person'>.

Django 使用两个不同的路径导入相同的模型.我该如何解决?

Django import the same model with two different pathes. How can I fix it?

完整的错误日志:

Traceback:
File "/home/voxa/.virtualenvs/42-test/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  98.                 resolver_match = resolver.resolve(request.path_info)
File "/home/voxa/.virtualenvs/42-test/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
  343.             for pattern in self.url_patterns:
File "/home/voxa/.virtualenvs/42-test/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
  372.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/voxa/.virtualenvs/42-test/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
  366.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
  37.     __import__(name)
File "/home/voxa/django/FortyTwoTestTask/fortytwo_test_task/urls.py" in <module>
  4. from resume import views
File "/home/voxa/django/FortyTwoTestTask/apps/resume/views.py" in <module>
  4. from resume.models import Person
File "/home/voxa/django/FortyTwoTestTask/apps/resume/models.py" in <module>
  3. class Person(models.Model):
File "/home/voxa/.virtualenvs/42-test/local/lib/python2.7/site-packages/django/db/models/base.py" in __new__
  285.         new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
File "/home/voxa/.virtualenvs/42-test/local/lib/python2.7/site-packages/django/apps/registry.py" in register_model
  213.                 (model_name, app_label, app_models[model_name], model))

Exception Type: RuntimeError at /
Exception Value: Conflicting 'person' models in application 'resume': <class 'apps.resume.models.Person'> and <class 'resume.models.Person'>.

推荐答案

不是先导入所有项目,然后导入应用程序,然后导入应用程序内部的模块,只需导入项目内部的应用程序,然后导入模块.

Instead of importing the all project then the app then the module inside the app just import the app which is inside the project then the module.

代替

from webproject.app import model

使用

from app import model

from app.models import Staffs

这篇关于Django 1.7 冲突模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆