I have tried many way to solve this, but none of them work. My question is when I tried to register a user, it shows an error no such table: auth_user . (py2.7 django 1.10)
I am using a custom user (because I want to add locations(one user can have multiple locations) to my users)
in my models.py:
from __future__ import unicode_literals
from django.conf import settings
from django.db import models
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import get_user_model
# Create your models here.
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
pass
class Locations(models.Model):
author = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
)
lat = models.FloatField(default=0.0)
lng = models.FloatField(default=0.0)
class UserForm(UserCreationForm):
class Meta:
model = User
fields = ("username",)
In my setting.py:
AUTH_USER_MODEL = 'weather.User'
# Application definition
INSTALLED_APPS = [
'weather',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
in my views.py:
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.views.generic.edit import CreateView
from django.contrib.auth.forms import UserCreationForm
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.template.context_processors import csrf
def register(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('register/complete')
else:
form = UserCreationForm()
token = {}
token.update(csrf(request))
token['form'] = form
return render_to_response('registration/register.html', token)
def registration_complete(request):
return render_to_response('registration/registration_complete.html')
I have tried
python manage.py makemigrations myapp
python manage.py migrate auth
python manage.py migrate
none of them helps, all same error.
Thanks!