get_profile() function can not resolve keyword 'user' -- no 'user' field exists in model.py or data tables.

72 views
Skip to first unread message

NoviceSortOf

unread,
Dec 7, 2016, 2:13:24 PM12/7/16
to Django users

While in the process of upgrading from 1.1 to 1.6

get_profile() returns a field error.
****************************************
Exception Type: FieldError
Exception Value: Cannot resolve keyword 'user' into field. Choices are: 
date_joined, email, first_name, groups, id, is_active, is_staff, is_superuser, last_login, last_name, logentry...
****************************************

On close inspection there is no 'user' field defined in  
_ myproject.profiles.models 
_ ...\site-packages\django\contrib\auth\models.py
_ or in the db auth_user or profile tables.

Drilling into all of the files listed in the traceback, (including site packages) 
I can find no instance of 'user' being assigned as a field.

*  Where else can I look to find 'user' and/or what is causing the problem.


Please advise 


*****************************
TRACEBACK
*****************************
Environment:

Request Method: GET

Django Version: 1.6.12
Python Version: 2.7.5
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'django.contrib.humanize',
 'django.contrib.redirects',
 'bookstor',
 'bookstor.registration',
 'bookstor.profiles',
 'django_extensions',
 'django.contrib.admin',
 'bookstor.cart')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.transaction.TransactionMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.contrib.redirects.middleware.RedirectFallbackMiddleware')


Traceback:
File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  120.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/var/www/MYPROJECT/data/bookstor/profiles/views.py" in create_profile
  49.         profile_obj = request.user.get_profile() ## If existing profile found 
File "/usr/lib/python2.7/site-packages/django/contrib/auth/models.py" in get_profile
  449.                 self._profile_cache = model._default_manager.using(self._state.db).get(user__id__exact=self.id)
File "/usr/lib/python2.7/site-packages/django/db/models/query.py" in get
  301.         clone = self.filter(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/django/db/models/query.py" in filter
  593.         return self._filter_or_exclude(False, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/django/db/models/query.py" in _filter_or_exclude
  611.             clone.query.add_q(Q(*args, **kwargs))
File "/usr/lib/python2.7/site-packages/django/db/models/sql/query.py" in add_q
  1204.         clause = self._add_q(where_part, used_aliases)
File "/usr/lib/python2.7/site-packages/django/db/models/sql/query.py" in _add_q
  1240.                     current_negated=current_negated)
File "/usr/lib/python2.7/site-packages/django/db/models/sql/query.py" in build_filter
  1103.                     allow_explicit_fk=True)
File "/usr/lib/python2.7/site-packages/django/db/models/sql/query.py" in setup_joins
  1363.             names, opts, allow_many, allow_explicit_fk)
File "/usr/lib/python2.7/site-packages/django/db/models/sql/query.py" in names_to_path
  1283.                                      "Choices are: %s" % (name, ", ".join(available)))

Exception Type: FieldError at /profiles/create/
Exception Value: Cannot resolve keyword 'user' into field. Choices are: date_joined, email, first_name, firstpass, groups, id, is_active, is_staff, is_superuser, last_login, last_name, logentry, password, registrationprofile, user_permissions, username

Alex Heyden

unread,
Dec 7, 2016, 3:12:50 PM12/7/16
to django...@googlegroups.com
The offending lines are these right here:

File "/var/www/MYPROJECT/data/bookstor/profiles/views.py" in create_profile
  49.         profile_obj = request.user.get_profile() ## If existing profile found 
File "/usr/lib/python2.7/site-packages/django/contrib/auth/models.py" in get_profile
  449.                 self._profile_cache = model._default_manager.using(self._state.db).get(user__id__exact=self.id)

Line 49 in profiles.views is calling get_profile on the user object. In turn, it's trying to dereference the user id in django.contrib.auth.models.

The get_profile() method is deprecated as of 1.5 (although not removed until 1.7). Your best bet is to stop using it in favor of custom user models (https://docs.djangoproject.com/en/1.10/releases/1.5/#auth-profile-module and https://docs.djangoproject.com/en/1.10/topics/auth/customizing/#auth-custom-user) because eventually you'll want to get yourself to a version of Django that's actually getting security updates.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/316b8d68-4bb1-426f-bb47-8c271dbe6bb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

NoviceSortOf

unread,
Dec 12, 2016, 2:52:52 PM12/12/16
to Django users

Thanks Alex,

Following the links you posted I've moved forward towards adding a custom user and getting rid of get_profile().

This process though has introduced other issues.

The error occurs both when running manage syncdb and when debugging view that calls user.
 
"AUTH_USER_MODEL refers to model 'books.user' that has not been installed"

My settings file clearly contains AUTH_USER_MODEL = 'books.user'

And class user is defined per instructions online regarding migrating to a custom user
inside of books.models.py.

It appears to me that user as defined in books.models.py is installed on the code level and am wondering where else the error message might be referencing that tells me it is not 'installed'.

Any suggested appreciated.

Thanks 

Alex Heyden

unread,
Dec 12, 2016, 3:08:03 PM12/12/16
to django...@googlegroups.com
The first place to look would be the INSTALLED_APPS setting in your settings file, but honestly that's one of those errors that could ultimately mean a lot of things. I've had it thrown on things ranging from circular imports to admin configuration issues to bad migrations. It might be time to spin up a debugger.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Darrell Jonsson

unread,
Dec 12, 2016, 3:23:54 PM12/12/16
to django...@googlegroups.com
Hi Alex,

Is there anyway on the command line I can determine what models,
the app actually sees in the module in question?

Otherwise can you recommend a debugger that might help.

Thanks




On 12/12/2016 9:07 PM, Alex Heyden wrote:
> The first place to look would be the INSTALLED_APPS setting in your
> settings file, but honestly that's one of those errors that could
> ultimately mean a lot of things. I've had it thrown on things ranging
> from circular imports to admin configuration issues to bad migrations.
> It might be time to spin up a debugger.
>
> On Mon, Dec 12, 2016 at 1:52 PM, NoviceSortOf <dljons...@gmail.com
> <mailto:dljons...@gmail.com>> wrote:
>
>
> Thanks Alex,
>
> Following the links you posted I've moved forward towards adding a
> custom user and getting rid of get_profile().
>
> This process though has introduced other issues.
>
> The error occurs both when running manage syncdb and when
> debugging view that calls user.
> "AUTH_USER_MODEL refers to model 'books.user' that has not been
> installed"
>
> My settings file clearly contains AUTH_USER_MODEL = 'books.user'
>
> And class user is defined per instructions online regarding
> migrating to a custom user
> inside of books.models.py <http://books.models.py>.
>
> It appears to me that user as defined in books.models.py
> <http://books.models.py> is installed on the code level and am
> wondering where else the error message might be referencing that
> tells me it is not 'installed'.
>
> Any suggested appreciated.
>
> Thanks
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> <https://groups.google.com/group/django-users>.
> <https://groups.google.com/d/msgid/django-users/afc26acd-3d2c-47ce-b696-4be15fb61357%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
>
> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/oPW7Vy2YNqY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2Bv0ZYVw-bUTLFJ65%2B7bgGLjeMz7RUtQ6g9sAj3MO73znwPP-A%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CA%2Bv0ZYVw-bUTLFJ65%2B7bgGLjeMz7RUtQ6g9sAj3MO73znwPP-A%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Alex Heyden

unread,
Dec 12, 2016, 3:41:26 PM12/12/16
to django...@googlegroups.com
Someone familiar with the internals might have an idea, but from a non-contributor's perspective, the different management commands seem to have different strategies for loading up the models. An error in syncdb doesn't mean you'll get the same error in shell or runserver.

Debuggers will always be a matter of personal preference, but I use the one in PyCharm.


    To post to this group, send email to django...@googlegroups.com
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com <mailto:django-users+unsubscrib...@googlegroups.com>.
To post to this group, send email to django...@googlegroups.com <mailto:django-users@googlegroups.com>.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages