Django-应用程序中的模型冲突,路径相同但大小写不同 [英] Django - Conflicting models in application, same path but different case

查看:44
本文介绍了Django-应用程序中的模型冲突,路径相同但大小写不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Django 1.8.我收到此错误:

Django 1.8. I'm getting this error:

Traceback (most recent call last):
[35mrentapp    | [0m  File "/home/rentapplication/django-rentapplication/manage.py", line 10, in <module>
[35mrentapp    | [0m    execute_from_command_line(sys.argv)
[35mrentapp    | [0m  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
[35mrentapp    | [0m    utility.execute()
[35mrentapp    | [0m  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 312, in execute
[35mrentapp    | [0m    django.setup()
[35mrentapp    | [0m  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
[35mrentapp    | [0m    apps.populate(settings.INSTALLED_APPS)
[35mrentapp    | [0m  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
[35mrentapp    | [0m    app_config.import_models(all_models)
[35mrentapp    | [0m  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 198, in import_models
[35mrentapp    | [0m    self.models_module = import_module(models_module_name)
[35mrentapp    | [0m  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[35mrentapp    | [0m    __import__(name)
[35mrentapp    | [0m  File "/home/rentapplication/django-rentapplication/accounts/models/__init__.py", line 3, in <module>
[35mrentapp    | [0m    from .landlord import Landlord
[35mrentapp    | [0m  File "/home/rentapplication/django-rentapplication/accounts/models/landlord.py", line 20, in <module>
[35mrentapp    | [0m    from accounting.models import Account
[35mrentapp    | [0m  File "/home/rentapplication/django-rentapplication/accounting/models/__init__.py", line 2, in <module>
[35mrentapp    | [0m    from .transaction import Transaction, RequestedWithdrawal
[35mrentapp    | [0m  File "/home/rentapplication/django-rentapplication/accounting/models/transaction.py", line 16, in <module>
[35mrentapp    | [0m    class Transaction(TimeStampedModel):
[35mrentapp    | [0m  File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 309, in __new__
[35mrentapp    | [0m    new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
[35mrentapp    | [0m  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 221, in register_model
[35mrentapp    | [0m    (model_name, app_label, app_models[model_name], model))
[35mrentapp    | [0mRuntimeError: Conflicting 'transaction' models in application 'accounting': <class 'accounting.models.Transaction.Transaction'> and <class 'accounting.models.transaction.Transaction'>.

我的结构如下:

accounting
  api
  migrations
  models
    __init__.py
    account.py
    transaction.py

init 中,我有以下代码:

from .account import Account
from .transaction import Transaction, RequestedWithdrawal

我不知道django在哪里提出了大写的交易程序包,我没有在代码中的任何地方使用它.那么,为什么会有这个错误,以及如何解决呢?

I have no idea from where django came up with upper cases transaction package, I didn't use it anywhere in my code. So why I'm having this error, and how to solve it?

更新.account.py导入

UPDATE. account.py imports

import StringIO
import csv
import logging
from decimal import Decimal

from django.conf import settings
from django.db import models
from django.db.models import Q
from django_extensions.db.models import TimeStampedModel
from notifications import notify

logger = logging.getLogger(__name__)
from accounting.tasks import notify_of_withdrawal_request_action

landlord.py进口

landlord.py imports

import datetime
import logging
from decimal import Decimal
from collections import Counter
import random
import string
import analytics

from django.utils.timezone import utc
from django.utils.functional import cached_property
from django.utils.timezone import now
from django.db import models, transaction
from django.contrib.auth.models import User
from django_extensions.db.models import TimeStampedModel
from easy_thumbnails.fields import ThumbnailerImageField
from jsonfield import JSONField
import stripe
from rentapplication.utils import generate_random_slug
from applications.models import ApplicationTemplate
from accounting.models import Account
from reports.models import  Report, ReportSourceProfile, ReportSource
from django.core.exceptions import ValidationError
from django.contrib.auth.tokens import default_token_generator
from django.conf import settings
import base64

transaction.py导入

transaction.py imports

import logging
from decimal import Decimal


logger = logging.getLogger(__name__)

from django.db import models
from django_fsm import FSMField, transition
from django_extensions.db.models import TimeStampedModel

from reports.models import Report

import stripe

推荐答案

我不知道为什么看到这种奇怪的错误消息和堆栈跟踪.但是问题出在models.py和tasks.py内部的循环导入.

I dont know why i was seeing this strange error message and stack trace. But the problem was with circular import inside models.py and tasks.py.

这篇关于Django-应用程序中的模型冲突,路径相同但大小写不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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