Cannot resolve keyword 'items' into field. Choices are: id, name

3.2k views Asked by At

I am using photologue to create a photo gallery site with django. I installed django-tagging into my virtualenv, not knowing it was no longer supported by photologue. Now, after having performed migrations, whenever I try to add a photo or view the photo, I get FieldError at /admin/photologue/photo/upload_zip/ Cannot resolve keyword 'items' into field. Choices are: id, name.

I uninstalled and reinstalled django, photologue, the SQLite file, and removed django-tagging, but the problem persists. I also tried running a different project that uses photologue and shares a virtualenv, and I am prompted to perform the same (assumedly destructive) migration.

I can't figure out what could have possibly changed on my system if the problem spans multiple projects and all the dependencies have been freshly installed.

Exception Location: /home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/db/models/sql/query.py in raise_field_error, line 1389

Traceback:

Environment:


Request Method: POST
Request URL: http://localhost:8000/admin/photologue/photo/add/

Django Version: 1.7.1
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'sortedm2m',
 'photologue',
 'photologue_custom',
 'pornsite')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
  584.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  105.                     response = view_func(request, *args, **kwargs)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  204.             return view(request, *args, **kwargs)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in add_view
  1454.         return self.changeform_view(request, None, form_url, extra_context)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  29.             return bound_func(*args, **kwargs)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  105.                     response = view_func(request, *args, **kwargs)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  25.                 return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/db/transaction.py" in inner
  394.                 return func(*args, **kwargs)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in changeform_view
  1405.                 self.save_model(request, new_object, form, not add)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in save_model
  1046.         obj.save()
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/photologue/models.py" in save
  540.         super(Photo, self).save(*args, **kwargs)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/photologue/models.py" in save
  491.         super(ImageModel, self).save(*args, **kwargs)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/db/models/base.py" in save
  591.                        force_update=force_update, update_fields=update_fields)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/db/models/base.py" in save_base
  628.                                    update_fields=update_fields, raw=raw, using=using)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py" in send
  198.             response = receiver(signal=self, sender=sender, **named)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/tagging/fields.py" in _save
  81.             Tag.objects.update_tags(kwargs['instance'], tags)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/tagging/models.py" in update_tags
  34.                                         items__object_id=obj.pk))
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/db/models/manager.py" in manager_method
  92.                 return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/db/models/query.py" in filter
  691.         return self._filter_or_exclude(False, *args, **kwargs)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/db/models/query.py" in _filter_or_exclude
  709.             clone.query.add_q(Q(*args, **kwargs))
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/db/models/sql/query.py" in add_q
  1287.         clause, require_inner = self._add_q(where_part, self.used_aliases)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/db/models/sql/query.py" in _add_q
  1314.                     current_negated=current_negated, connector=connector)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/db/models/sql/query.py" in build_filter
  1138.         lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/db/models/sql/query.py" in solve_lookup_type
  1076.         _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/db/models/sql/query.py" in names_to_path
  1383.             self.raise_field_error(opts, name)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/db/models/sql/query.py" in raise_field_error
  1389.                          "Choices are: %s" % (name, ", ".join(available)))

Exception Type: FieldError at /admin/photologue/photo/add/
Exception Value: Cannot resolve keyword 'items' into field. Choices are: id, name
2

There are 2 answers

0
andzep On BEST ANSWER

The problem seems to arise from the fact, that django-tagging was somehow still present on the virtualenv.

In your traceback after photologue saves a model, django-tagging reacts to the sent signal and tries to update any related tags:

File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py" in send
  198.             response = receiver(signal=self, sender=sender, **named)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/tagging/fields.py" in _save
  81.             Tag.objects.update_tags(kwargs['instance'], tags)
File "/home/cameron/Envs/photologue/local/lib/python2.7/site-packages/tagging/models.py" in update_tags
  34.                                         items__object_id=obj.pk))

There it tries to use the (apparently not existing anymore) field items, and that's where the error occurs.

I guess the way you deinstalled django-tagging on the venv didn't really work. Did you uninstalled with: pip uninstall django-tagging ?

For reference, here again my comment/steps to recreate the venv

... If your venv is somehow corrupted, the easiest could be to recreate it from scratch:

  1. On your venv do:

    env pip freeze > orig_requirements.txt

    Check the orig_requirements.txt and delete everything you don't need.

  2. Make a new venv with no site-packages and reinstall the requirements:

    mkvirtualenv --no-site-packages photoenv

    pip install -r orig_requirements.txt

  3. Now double check you're on this venv when running your django project

    workon photoenv

5
shark3y On

Well the error is simple -- in that you are requesting a field in the database that does not exist. Since you haven't posted code it is hard to be more specific than that. Was one of your templates built, referencing a field named 'items' that is no longer there?

Please edit your question to include a FULL traceback as well as some code where you think the problem could be.

The full traceback will give you a better idea of where the problem is.