2014-10-27 119 views
20

我在「project/apps/myapp」文件夾中安裝我的應用程序。這兩個應用程序和myapp文件夾都有init .py文件(沒有任何一個模塊缺少錯誤)。現在,我的錯誤:Django 1.7衝突模型

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

Django的進口機型相同的兩個不同的pathes。我該如何解決它?

完整的錯誤日誌:

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'>. 
+0

你有 「恢復」 無論是在_project/resume_和_project /應用/ resume_應用程序? – dukebody 2014-10-27 17:25:15

+0

不僅「項目/應用程序/簡歷」 – Crampus 2014-10-27 17:51:00

+0

你可以做'從apps.resume.models導入Person爲Person1;從resume.models導入Person作爲Person2;打印Person1 .__ file__;打印Person2 .__ file__'並在這裏發佈結果? – dukebody 2014-10-28 08:26:19

回答

7

,而不是導入所有項目,然後將應用程序,然後在應用程序中的模塊只需要導入的應用程序,它是內部的該項目然後是模塊。

而不是

from webproject.app import model 

使用

from app import model 

from app.models import Staffs 
4

我覺得this bug report(原來它是一個功能)是關係到你的問題。

對我來說,問題只能通過從resume.models導入而不是apps.resume.models來解決。因此,在您的項目中搜索"from apps."並將其替換。

(對於我來說,除去__init__.py或改變PYTHONPATH引起其他的問題,我想這是常見的。)