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

user2988464 :

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?

ruddra :

Update

You are probably getting this error because you are using UserCreationForm modelform, in which in META it contains User(django.contrib.auth.models > User) as model.

class Meta:
    model = User
    fields = ("username",)

And here you are using your own custom auth model, so tables related to User has not been created. So here you have to use your own custom modelform. where in Meta class, model should be your User(books.User) model

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Django superuser fixture error - no such table: auth_user

Password not saving to auth_user table in Django

Django Setup: No Such Table auth_user

unable to create superuser in django getting error "django.db.utils.OperationalError: no such table: auth_user"

merge django's auth_user with existing user table

Creating a New Table (Model) and Relating it to auth_user in Django

Django testing on separate database giving "OperationalError: no such table: auth_user"

Graphite Web Error Log, OperationalError: no such table: auth_user

How to add 'mobile' field to default auth_user table in User model in django?

Error Key (user_id)=(1) is not present in table "auth_user" when migrating

Is it safe to share `auth_user` and `django_session` table for intranet Django projects?

Django deployment on heroku throws django.db.utils.OperationalError: no such table: auth_user

how to update django auth_user with queryset?

Django add field to auth_user

Django.. I need to have a DateField which should be updated when auth_user table gets updated

I'd like to get some data from auth_user table on Django

Django: How do I use is_active of auth_user table?

django application on heroku gives 'Programming error at /admin/login "auth_user" does not exist.' on login

PyroCMS user registration error

How to add columns to auth_user in django postgresql?

User registration fully not working in Django

Django user registration without username

django rest framework user registration

Django rest framework user registration?

signal for custom user registration in django

Fill user profile on user registration with Django

Django User Registration with custom user model

Django REST Framework and python-social-auth for registration/login user

Using django-rest-auth registration with multiple user types