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

Posted on

Question :

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

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.




AUTH_USER_MODEL = 'books.User'


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


from django.contrib.auth.forms import UserCreationForm

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


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 syncdb, there’s still this error message:

OperationalError at /accounts/register/
no such table: auth_user
Request Method: POST
Request URL:
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 #1:


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

Answered By: ruddra

Answer #2:

./ migrate

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

Answered By: jmoz

Answer #3:

Only thing you need to do is :

python migrate

and after that:

python createsuperuser

after that you can select username and password.

here is the sample output:

Username (leave blank to use 'hp'): admin
Email address:
Password (again):
Superuser created successfully.
Answered By: Rajiv Sharma

Answer #4:

This will work for django version <1.7:

Initialize the tables with the command syncdb

This allows you to nominate a “super user” as well as initializing any tables.

Answered By: holdenweb

Answer #5:

it is need to make migration before create superuser.

python makemigrations
python migrate
python createsuperuser
Username : admin
Password : 12345678

python runserver

Answered By: Zin Myo Swe

Answer #6:

If using a custom auth model, in your UserCreationForm subclass, you’ll have to override both the metaclass and clean_username method as it references a hardcoded User class (the latter just until django 1.8).

class Meta(UserCreationForm.Meta):
        model = get_user_model()

    def clean_username(self):
        username = self.cleaned_data['username']

        except self.Meta.model.DoesNotExist:
            return username

        raise forms.ValidationError(
Answered By: Kukosk

Answer #7:

Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
try running

python migrate

then run

python createsuperuser
Answered By: Leman Kirme

Answer #8:

Just perform migrations before registering the user.

Answered By: randhir gupta

Leave a Reply

Your email address will not be published. Required fields are marked *