Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django.core.exceptions.ImproperlyConfigured

I have recently moved to another machine and have had to check my project out from subversion again, but I am pretty sure this computer has Django 1.8 and the project is expecting 1.7.

I have tried to sync my db with the code to create the necessary tables but I get the following error.

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.
like image 365
Jon Avatar asked Sep 29 '14 15:09

Jon


2 Answers

Like the error mentions, you need to explicitly specify the fields, or exclude.

Try this

class JobForm(models.ModelForm):
    #fields

    class Meta:
        model = Job
        fields = "__all__" 

which would include all the fields

Here is the relevant documentation (release notes 1.6)

Previously, if you wanted a ModelForm to use all fields on the model, you could simply omit the Meta.fields attribute, and all fields would be used.

This can lead to security problems where fields are added to the model and, unintentionally, automatically become editable by end users. In some cases, particular with boolean fields, it is possible for this problem to be completely invisible. This is a form of Mass assignment vulnerability.

For this reason, this behavior is deprecated, and using the Meta.exclude option is strongly discouraged. Instead, all fields that are intended for inclusion in the form should be listed explicitly in the fields attribute.

If this security concern really does not apply in your case, there is a shortcut to explicitly indicate that all fields should be used - use the special value "__all__" for the fields attribute

like image 60
karthikr Avatar answered Oct 20 '22 17:10

karthikr


You can set fields or exclude in the ModelForm in Django 1.7. It changes in 1.8, you should set fields or exclude in the Meta class within ModelForm.

class JobForm(models.ModelForm):
#fields

class Meta:
    model = Job
    fields = "__all__" 
like image 40
david euler Avatar answered Oct 20 '22 17:10

david euler