我最近搬到另一台机器,不得不再次从subversion检查我的项目,但我很确定这台计算机有Django 1.8,项目期待1.7。
我尝试将我的数据库与代码同步以创建必要的表,但是我收到以下错误。
C:\Users\jont\Documents\ATP\Webapp>manage.py syncdb
C:\Python27\lib\site-packages\admin_tools\utils.py:9: RemovedInDjango19Warning:
django.utils.importlib will be removed in Django 1.9.
from django.utils.importlib import import_module
c:\users\jont\documents\django-trunk\django\contrib\contenttypes\models.py:148:
RemovedInDjango19Warning: Model class django.contrib.contenttypes.models.ContentType doesn't de
her isn't in an application in INSTALLED_APPS or else was imported before its application was
loaded. This will no longer be supported in Django 1.9.
class ContentType(models.Model):
C:\Python27\lib\site-packages\admin_tools\dashboard\modules.py:8: RemovedInDjango19Warning: The
django.forms.util module has been renamed. Use django.forms.utils instead.
from django.forms.util import flatatt
C:\Python27\lib\site-packages\django_tables2\tables.py:171: RemovedInDjango19Warning: SortedDict
is deprecated and will be removed in Django 1.9. attrs["base_columns"] =
SortedDict(parent_columns)
C:\Python27\lib\site-packages\django_tables2\tables.py:193: RemovedInDjango19Warning: SortedDict
is deprecated and will be removed in Django 1.9.
attrs["base_columns"].update(SortedDict(cols))
Traceback (most recent call last):
File "C:\Users\jont\Documents\ATP\Webapp\manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "c:\users\jont\documents\django-trunk\django\core\management\__init__.py", line 336, in
execute_from_command_line
utility.execute()
File "c:\users\jont\documents\django-trunk\django\core\management\__init__.py", line 310, in
execute
django.setup()
File "c:\users\jont\documents\django-trunk\django\__init__.py", line 23, in setup
apps.populate(settings.INSTALLED_APPS)
File "c:\users\jont\documents\django-trunk\django\apps\registry.py", line 115, in populate
app_config.ready()
File "c:\users\jont\documents\django-trunk\django\contrib\admin\apps.py", line 22, in ready
self.module.autodiscover()
File "c:\users\jont\documents\django-trunk\django\contrib\admin\__init__.py", line 24, in
autodiscover
autodiscover_modules('admin', register_to=site)
File "c:\users\jont\documents\django-trunk\django\utils\module_loading.py", line 73, in
autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\jont\Documents\ATP\Webapp\jobs\admin.py", line 4, in <module>
from jobs.views import registration
File "C:\Users\jont\Documents\ATP\Webapp\jobs\views.py", line 12, in <module>
from jobs.forms import ApplicantForm, JobForm, \
File "C:\Users\jont\Documents\ATP\Webapp\jobs\forms.py", line 8, in <module>
class JobForm(forms.ModelForm):
File "c:\users\jont\documents\django-trunk\django\forms\models.py", line 272, in __new__
"needs updating." % name
django.core.exceptions.ImproperlyConfigured: Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is prohibited; form JobForm needs updating.
django.core.exceptions.ImproperlyConfigured: Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is prohibited; form JobForm needs updating.
答案 0 :(得分:65)
与错误提及类似,您需要明确指定字段或排除。
试试这个
class JobForm(models.ModelForm):
#fields
class Meta:
model = Job
fields = "__all__"
包括所有字段
以下是相关的documentation (release notes 1.6)
以前,如果您希望ModelForm使用模型上的所有字段, 你可以简单地省略Meta.fields属性,所有字段都可以 使用。
这可能会导致将字段添加到模型中的安全问题 并且,无意中,最终用户可以自动编辑。在 在某些情况下,特别是布尔字段,这是可能的 问题是完全看不见的。这是一种质量分配形式 漏洞。
出于这个原因,不推荐使用此行为,并使用 强烈建议不要使用Meta.exclude选项。相反,所有领域 旨在列入表格的内容应明确列出 fields属性。
如果此安全问题确实不适用于您的情况,则有 显式指示应使用所有字段的快捷方式 - 使用 字段属性
的特殊值“__all__
”
答案 1 :(得分:5)
您可以在Django 1.7中的ModelForm中设置字段或排除。 它在1.8中变化,你应该在ModelForm中的Meta类中设置字段或排除。
class JobForm(models.ModelForm):
#fields
class Meta:
model = Job
fields = "__all__"
答案 2 :(得分:-6)
放弃到Django 1.7似乎可以解决问题。似乎没有一种简单的方法可以使代码适应Django 1.8。