django: User Registration with error: no such table: auth_user

user2988464 picture user2988464 · Jul 10, 2014 · Viewed 83.1k times · Source

I try to use Django's default Auth to handle register and login. And I think the procedure is pretty standard, but mine is with sth wrong.

my setting.py:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'books',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

AUTH_USER_MODEL = 'books.User'

my books.models.py:

class User(AbstractUser):
    account_balance = models.DecimalField(max_digits=5, decimal_places=2, default=0)

my views.py:

from django.contrib.auth.forms import UserCreationForm

def register(request):
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            return HttpResponseRedirect("/accounts/profile/")
    else:
        form = UserCreationForm()
    return render(request, "registration/register.html", {'form': form,})

my urls.py

urlpatterns = patterns('',
    (r'^accounts/login/$', login),
    (r'^accounts/logout/$', logout),
    (r'^accounts/profile/$', profile),
    (r'^accounts/register/$', register),
)

Even I tried delete the db.sqlite3 and re python manage.py syncdb, there's still this error message:

OperationalError at /accounts/register/
no such table: auth_user
Request Method: POST
Request URL:    http://127.0.0.1:8000/accounts/register/
Django Version: 1.7b4
Exception Type: OperationalError
Exception Value:    
no such table: auth_user

Can someone explain and tell me what I should do?

Answer

jmoz picture jmoz · Sep 23, 2015
./manage.py migrate

If you've just enabled all the middlewares etc this will run each migration and add the missing tables.