Chapt 10 migrating database --cannot import name user


#1

On page 78, after the comment line
$ python manage.py makemigrations
$ python manage.py migrate
(my venv should be on)

My Terminal responded:

/Users/Ket/projects/hellowebapp/venv/lib/python2.7/site-packages/django/contrib/sites/models.py:78: RemovedInDjango19Warning: Model class django.contrib.sites.models.Site doesn’t declare an explicit app_label and either 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 Site(models.Model):

System check identified some issues:

WARNINGS:
registration.RegistrationProfile.user: (fields.W342) Setting unique=True on a ForeignKey has the same effect as using a OneToOneField.
HINT: ForeignKey(unique=True) is usually better served by a OneToOneField.
Migrations for ‘collection’:
0002_thing_user.py:
- Add field user to thing
(venv)Ketings-MacBook-Air:hellowebapp Ket$ python manage.py migrate
/Users/Ket/projects/hellowebapp/venv/lib/python2.7/site-packages/django/contrib/sites/models.py:78: RemovedInDjango19Warning: Model class django.contrib.sites.models.Site doesn’t declare an explicit app_label and either 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 Site(models.Model):

System check identified some issues:

WARNINGS:
registration.RegistrationProfile.user: (fields.W342) Setting unique=True on a ForeignKey has the same effect as using a OneToOneField.
HINT: ForeignKey(unique=True) is usually better served by a OneToOneField.
Operations to perform:
Synchronize unmigrated apps: staticfiles, humanize, messages, registration
Apply all migrations: admin, contenttypes, collection, auth, sessions
Synchronizing apps without migrations:
Creating tables…
Creating table registration_registrationprofile
Running deferred SQL…
Installing custom SQL…
Running migrations:
Rendering model states… DONE
Applying collection.0002_thing_user… OK
(venv)Ketings-MacBook-Air:hellowebapp Ket$

My web page failed to load “This webpage is not available”, and below is the error message in my terminal:

Traceback (most recent call last):
File “manage.py”, line 10, in
execute_from_command_line(sys.argv)
File “/Users/Ket/projects/hellowebapp/venv/lib/python2.7/site-packages/django/core/management/init.py”, line 338, in execute_from_command_line
utility.execute()
File “/Users/Ket/projects/hellowebapp/venv/lib/python2.7/site-packages/django/core/management/init.py”, line 312, in execute
django.setup()
File “/Users/Ket/projects/hellowebapp/venv/lib/python2.7/site-packages/django/init.py”, line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File “/Users/Ket/projects/hellowebapp/venv/lib/python2.7/site-packages/django/apps/registry.py”, line 108, in populate
app_config.import_models(all_models)
File “/Users/Ket/projects/hellowebapp/venv/lib/python2.7/site-packages/django/apps/config.py”, line 198, in import_models
self.models_module = import_module(models_module_name)
File “/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/init.py”, line 37, in import_module
import(name)
File “/Users/Ket/projects/hellowebapp/collection/models.py”, line 1, in
from django.contrib.auth.models import user
ImportError: cannot import name user


#2

Looks like you’re using Django 1.9 — Hello Web App has not been tested with 1.9 yet. Can you uninstall it and try it with Django==1.8.4 and let me know if you get the same error? Use pastebin.com to share the text.


#3

Thanks for your respond. I checked my django version, and it is 1.84 not 1.9
$ python
Python 2.7.10 (default, Sep 23 2015, 04:34:14)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

import django
django.get_version()
‘1.8.4’


#4

Whoops, you’re right.

Can you paste your models.py into pastebin.com for me?


#5

Thanks for your response. here is the link to my models.py
http://pastebin.com/T7eJCD7D

and my urls.py
http://pastebin.com/RcqLrevV


#6

Thanks! You listed two commands at the top, makemigrations and migrate. Which of these did the error happen on?


#7

Oh also — did you make sure you were in your Virtual Environment?