无法从django.db.models导入SubfieldBase导入SubfieldBase

时间:2017-01-03 09:39:30

标签: python django

我试图摆脱错误,无法找到解决方法的线索。请告知,因为我在不同的软件包中看到了一些修复,但没有一个是相关的。

回溯:

Traceback (most recent call last):
  File "C:\Users\AliKhan\supermarekt\market\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
367, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
341, in execute
    django.setup()
  File "C:\Python27\lib\site-packages\django\__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Python27\lib\site-packages\django\apps\registry.py", line 85, in popu
late
    app_config = AppConfig.create(entry)
  File "C:\Python27\lib\site-packages\django\apps\config.py", line 90, in create

    module = import_module(entry)
  File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "C:\Users\AliKhan\supermarekt\market\catalogue\__init__.py", line 4, in
<module>
    from django.db.models import SubfieldBase
ImportError: cannot import name SubfieldBase

在我的Catalouge软件包中,我只是简单地导入它并导入失败。

from django.core.exceptions import ImproperlyConfigured
from django.db.models.fields import CharField, DecimalField
from django.db.models import SubfieldBase
from django.utils import six
from django.utils.translation import ugettext_lazy as _

Django SubfieldBase的源代码如下所示,位于Django 1.8.16版的djagno.db.models.subclassing.py。

import warnings

from django.utils.deprecation import RemovedInDjango110Warning


class SubfieldBase(type):
    """
    A metaclass for custom Field subclasses. This ensures the model's attribute
    has the descriptor protocol attached to it.
    """
    def __new__(cls, name, bases, attrs):
        warnings.warn("SubfieldBase has been deprecated. Use Field.from_db_value instead.",
                  RemovedInDjango110Warning, stacklevel=2)

        new_class = super(SubfieldBase, cls).__new__(cls, name, bases, attrs)
        new_class.contribute_to_class = make_contrib(
            new_class, attrs.get('contribute_to_class')
        )
        return new_class

1 个答案:

答案 0 :(得分:1)

这很奇怪,但现在经常发生这种情况。在Windows 10中,如果我创建virtualenv并安装与全局安装不同的djagno版本,它仍然是服务器全局安装的属性。我甚至尝试使用--no-site-packages,但行为仍然相同而且有问题。我在全球删除了1.10,现在问题已修复。