简体   繁体   English

升级到Django 1.9或1.11(从1.6) - 调用元类库时出错

[英]Upgrade to Django 1.9 or 1.11 (from 1.6) - Error when calling the metaclass bases

I am upgrading to django 1.9 (from 1.6) 我升级到django 1.9(从1.6)

mysql-connector-python 2.1.6 is installed 安装了mysql-connector-python 2.1.6

when I try to run my app, I get: 当我尝试运行我的应用程序时,我得到:

TypeError: Error when calling the metaclass bases
    'NoneType' object is not callable

Has anyone had this issue? 有人有这个问题吗?

stacktrace: 堆栈跟踪:

/Library/Python/2.7/site-packages/django/core/handlers/wsgi.pyc in __init__(self, *args, **kwargs)
    149     def __init__(self, *args, **kwargs):
    150         super(WSGIHandler, self).__init__(*args, **kwargs)
--> 151         self.load_middleware()
    152 
    153     def __call__(self, environ, start_response):

/Library/Python/2.7/site-packages/django/core/handlers/base.pyc in load_middleware(self)
     55             for middleware_path in settings.MIDDLEWARE_CLASSES:
     56                 print middleware_path
---> 57                 mw_class = import_string(middleware_path)
     58                 try:
     59                     mw_instance = mw_class()

/Library/Python/2.7/site-packages/django/utils/module_loading.pyc in import_string(dotted_path)
     18         six.reraise(ImportError, ImportError(msg), sys.exc_info()[2])
     19 
---> 20     module = import_module(module_path)
     21 
     22     try:

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.pyc in import_module(name, package)
     35             level += 1
     36         name = _resolve_name(name[level:], package, level)
---> 37     __import__(name)
     38     return sys.modules[name]

/Library/Python/2.7/site-packages/django/contrib/auth/middleware.py in <module>()
      2 from django.contrib import auth
      3 from django.contrib.auth import load_backend
----> 4 from django.contrib.auth.backends import RemoteUserBackend
      5 from django.core.exceptions import ImproperlyConfigured
      6 from django.utils.deprecation import MiddlewareMixin

/Library/Python/2.7/site-packages/django/contrib/auth/backends.py in <module>()
      2 
      3 from django.contrib.auth import get_user_model
----> 4 from django.contrib.auth.models import Permission
      5 
      6 UserModel = get_user_model()

/Library/Python/2.7/site-packages/django/contrib/auth/models.py in <module>()
      2 
      3 from django.contrib import auth
----> 4 from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
      5 from django.contrib.auth.signals import user_logged_in
      6 from django.contrib.contenttypes.models import ContentType

/Library/Python/2.7/site-packages/django/contrib/auth/base_user.py in <module>()
     50 
     51 @python_2_unicode_compatible
---> 52 class AbstractBaseUser(models.Model):
     53     password = models.CharField(_('password'), max_length=128)
     54     last_login = models.DateTimeField(_('last login'), blank=True, null=True)

/Library/Python/2.7/site-packages/django/db/models/base.pyc in __new__(cls, name, bases, attrs)
    122                 app_label = app_config.label
    123 
--> 124         new_class.add_to_class('_meta', Options(meta, app_label))
    125         if not abstract:
    126             new_class.add_to_class(

/Library/Python/2.7/site-packages/django/db/models/base.pyc in add_to_class(cls, name, value)
    328         # We should call the contribute_to_class method only if it's bound
    329         if not inspect.isclass(value) and hasattr(value, 'contribute_to_class'):
--> 330             value.contribute_to_class(cls, name)
    331         else:
    332             setattr(cls, name, value)

/Library/Python/2.7/site-packages/django/db/models/options.pyc in contribute_to_class(self, cls, name)
    212         if not self.db_table:
    213             self.db_table = "%s_%s" % (self.app_label, self.model_name)
--> 214             self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
    215 
    216     def _prepare(self, model):

/Library/Python/2.7/site-packages/django/db/__init__.pyc in __getattr__(self, item)
     31     """
     32     def __getattr__(self, item):
---> 33         return getattr(connections[DEFAULT_DB_ALIAS], item)
     34 
     35     def __setattr__(self, name, value):

/Library/Python/2.7/site-packages/django/db/utils.pyc in __getitem__(self, alias)
    210         db = self.databases[alias]
    211         backend = load_backend(db['ENGINE'])
--> 212         conn = backend.DatabaseWrapper(db, alias)
    213         setattr(self._connections, alias, conn)
    214         return conn

/Library/Python/2.7/site-packages/mysql/connector/django/base.pyc in __init__(self, *args, **kwargs)
    334 
    335     def __init__(self, *args, **kwargs):
--> 336         super(DatabaseWrapper, self).__init__(*args, **kwargs)
    337 
    338         try:

/Library/Python/2.7/site-packages/django/db/backends/base/base.pyc in __init__(self, settings_dict, alias, allow_thread_sharing)
     94         self.run_commit_hooks_on_set_autocommit_on = False
     95 
---> 96         self.client = self.client_class(self)
     97         self.creation = self.creation_class(self)
     98         self.features = self.features_class(self)

TypeError: Error when calling the metaclass bases
    'NoneType' object is not callable

Update: i added 更新:我补充说

client_class = DatabaseClient 
creation_class = DatabaseCreation
features_class = DatabaseFeatures
introspection_class = DatabaseIntrospection
ops_class = DatabaseOperations
validation_class = DatabaseValidation 

in mysql/connecotr/django/base.py at DatabaseWrapper (looks like missing? - its there on django1.11/db/backends/mysql/base.py DatabaseWrapper). 在DatabaseWrapper的mysql / connecotr / django / base.py中(看起来像丢失了? - 它在django1.11 / db / backends / mysql / base.py DatabaseWrapper上)。 but now i get the error: 但现在我得到错误:

 Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS

so i dont know if this solved the issue or created a new one 所以我不知道这是否解决了问题或创建了新问题

Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS 模型类django.contrib.contenttypes.models.ContentType不声明显式的app_label,也不在INSTALLED_APPS的应用程序中

This error generally happens when your apps get imported before the settings files are completely imported (ie before the initialization of INSTALLED_APPS, which happen after settings have finished importing). 在完全导入设置文件之前(即在设置完成导入后发生的INSTALLED_APPS初始化之前)导入应用程序时,通常会发生此错误。 So make sure you don't have any code in settings file, which imports code from some other apps. 因此,请确保您在设置文件中没有任何代码,该文件从其他应用程序导入代码。

Also ensure that you are not importing models or similar app code, in __init__.py files of your apps, such that there imports are not automatically triggered at settings level. 还要确保您没有在应用的__init__.py文件中导入模型或类似的应用代码,以便在设置级别不会自动触发导入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM