Ali khan
Ali khan

Reputation: 585

Cannot import SubfieldBase from django.db.models import SubfieldBase

I am trying to get rid of the error and couldn't find a clue how to fix it. Please advise because I've seen few fixes in different packages but none of them are relevant.

Traceback:

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

In my Catalouge package I've just simply imported it and import is getting failed.

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 Source code for SubfieldBase is following that lies at djagno.db.models.subclassing.py for Django version 1.8.16.

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

Upvotes: 0

Views: 2094

Answers (1)

Ali khan
Ali khan

Reputation: 585

This is weird but it is happening more often now. In Windows 10 if I create virtualenv and install djagno version different than global installation it still servers attributes of global installation. I even tried with --no-site-packages but behavior is still same and its problematic. I removed 1.10 globally and now issues is fixed.

Upvotes: 1

Related Questions