User Registration with error: no such table: auth_user

All we need is an easy explanation of the problem, so here it is.

I am trying to use Django’s default Auth to handle register and log in.



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),

I tried deleting the db.sqlite3 file and re-ran python syncdb but I still get 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

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

./ migrate

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

Method 2

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: [email protected]
Password (again):
Superuser created successfully.

Method 3


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

Method 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.

Method 5

it is need to make migration before create superuser.

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

python runserver

Method 6

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

Method 7

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(

Method 8

Before creating a custom user model, a first migration must be performed. Then install the application of your user model and add the AUTH_USER_MODEL.

As well:

class UserForm(UserCreationForm):

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


python migrate auth
python migrate

Method 9

For custom forms( if you have made your own forms) use this command to migrate

python migrate –run-syncdb

Method 10

On Django 1.11 I had to do this after following instructions in docs

# create default database:
./ migrate

# create my custom model migration:
# running `./ makemigrations` was not enough
./ makemigrations books
# specify one-off defaults

# create table with users:
./ migrate

Method 11

Just do the following flow

$ django-admin createproject <your project name>

under <your project dict> type django-admin createapp <app name>

under <app name>/

from django.contrib import admin
from .models import Post

Go to the root project. Then $python migrate

Then it asks for username and password

Method 12

Just perform migrations before registering the user.

Method 13

theres four steps for adding a custom user model to django

  1. Create a CustomUser model
  2. update project/ AUTH_USER_MODEL
  3. customize UserCreationForm & UserChangeForm
  4. add the custom user model to

you missed customize forms , add the CustomUser and CustomUserAdmin to , then makemigrations nd migrate .

from django.contrib.auth import get_user_model
from django.contrib.auth.forms import UserCreationForm, UserChangeForm

class CustomUserCreationForm(UserCreationForm):
    class Meta:
            model = get_user_model()
            fields = ('email','username',)

class CustomUserChangeForm(UserChangeForm):
    class Meta:
            model = get_user_model()
            fields = ('email',  'username',)

from django.contrib import admin
from django.contrib.auth import get_user_model
from django.contrib.auth.admin import UserAdmin

from .forms import CustomUserCreationForm , CustomUserChangeForm

CustomUser = get_user_model()

class CustomUserAdmin(UserAdmin):
    add_form = CustomUserCreationForm
    form = CustomUserChangeForm
    model = CustomUser
    list_display = ['email','username',], CustomUserAdmin)

here we extend the existing UserAdmin into CustomUserAdmin and tell django to use our new forms, custom user model, and list only the email and username of a user also we could add more of existing User fields to list_display

Method 14

I have also faced the same problem “no such table: auth_user” when I was trying to deploy one of my Django website in a virtual environment.

Here is my solution which worked in my case:

In your file where you defined your database setting like this:

    'default': {
        'ENGINE': 'django.db.backends.sqlite3',

        'NAME': os.path.join(os.getcwd(), 'db.sqlite3'),

just locate your db.sqlite3 database or any other database that you are using and write down a full path of your database , so the database setting will now look something like this ;

    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': '/home/django/django_project/db.sqlite3',

I hope that your problem will resolve now.

Method 15

python makemigrations then → python migrate fixes it.

Assuming Apps defined/installed in exist in the project directory.

Method 16

Please check how many python instances are running in background like in windows go—>task manager and check python instances and kill or end task i.e kill all python instances. run again using “py runserver” command.
i hope it will be work fine….

Method 17

If You did any changes in project/app then execute:

python migrate
python makemigrations
python createsuperuser

Method 18

call these command

python makemigrations
python migrate

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply