2017-08-07 77 views
0

我正在使用django的旧版本创建的django项目。我的环境设置为最新的django版本(1.11.4)。 当我尝试python manage.py runserver,我得到这个:Django AttributeError:'模块'对象没有属性'SubfieldBase'

Unhandled exception in thread started by Traceback (most recent call last): File

"/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 228, in wrapper

fn(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", 

line 117, in inner_run

autoreload.raise_last_exception() File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", 

line 251, in raise_last_exception

six.reraise(*_exception) File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", 

line 228, in wrapper

fn(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 27, 

in setup

apps.populate(settings.INSTALLED_APPS) File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 

108, in populate

app_config.import_models() File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 

202, in import_models

self.models_module = import_module(models_module_name) File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module 
__import__(name) File 

"/home/ahmedn1/Documents/Paymob/wallet_executive_panel-master-c109bd6fe9cd1bf793c11a5c2e97d18a1887c3ba/accounts/models.py", line 8, in

import timedelta File "/usr/local/lib/python2.7/dist-packages/timedelta/__init__.py", line 

11, in

from .fields import TimedeltaField File "/usr/local/lib/python2.7/dist-packages/timedelta/fields.py", line 18, 

in

class TimedeltaField(six.with_metaclass(models.SubfieldBase, models.Field)): AttributeError: 'module' object has no attribute 

'SubfieldBase'

所以,看来问题是与Django的timedeltafield包。我有该软件包的最新版本(0.7.10)。所以,我不明白为什么它仍然有一个问题与废弃的SubfieldBase。

任何想法我可以如何解决这个问题?

回答

0

django-timedelta字段包不能用于Django 1.10+。从django-timedelta-field回购:

If you are using Django 1.8 or greater (and you really should be), then you should use the included DurationField() instead of this.

This field does not work with Django 1.10, and will probably not be updated to fix the issue(s).

下面是SubFieldBase1.8 release notes弃用的解释。

+0

是的,但那段代码在django模块本身内部。这不在我的项目中。 我该如何改变? 我的意思是'从.fields导入TimedeltaField文件“/usr/local/lib/python2.7/dist-packages/timedelta/fields.py”,第18行,' – Ahmedn1

+0

我不明白你的问题。建议是在Django 1.10+中使用'DurationField()'而不是'django-timedelta-field'。如果你想使用django-timedelta字段,你必须在安装之前克隆版本库并修改代码。 – Alasdair

+0

好吧,我明白了。我删除了所有导入的timedelta,并在迁移文件中使用了models.DurationField。 这解决了这个问题。 – Ahmedn1

相关问题