Code Monkey home page Code Monkey logo

Comments (8)

benregn avatar benregn commented on May 10, 2024 18

@raushanraj did you run python manage.py migrate (for Django 1.7) or python manage.py syncdb and then python manage.py migrate (for Django 1.6)?

from cookiecutter-django.

raushanraj avatar raushanraj commented on May 10, 2024

@benregn yes,I run python manage.py migrate.nothing to migrate now.

from cookiecutter-django.

raushanraj avatar raushanraj commented on May 10, 2024

I follow step by step from documentation.Every thing is working fine.User Login,User Regestration.But When Admin add user it throws error mentioned aboved.I tried two times the documentation but is not working

from cookiecutter-django.

raushanraj avatar raushanraj commented on May 10, 2024

https://code.djangoproject.com/ticket/19353 please see this issue.some problem in users admin.py .

from cookiecutter-django.

hanneshapke avatar hanneshapke commented on May 10, 2024

I ran into the same trouble. With the help of this blog post, I managed to fix it. My admin.py looks now like this:

# -*- coding: utf-8 -*-
from django.contrib import admin
from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
from .models import User


class MyUserCreationForm(UserCreationForm):
    def clean_username(self):
        username = self.cleaned_data["username"]
        try:
            User._default_manager.get(username=username)
        except User.DoesNotExist:
            return username
        raise forms.ValidationError(self.error_messages['duplicate_username'])

    class Meta(UserCreationForm.Meta):
        model = User


class UserAdmin(AuthUserAdmin):
    add_form = MyUserCreationForm
    update_form_class = UserChangeForm


admin.site.register(User, UserAdmin)

from cookiecutter-django.

KushGoyal avatar KushGoyal commented on May 10, 2024

thanks!

from cookiecutter-django.

eeriksp avatar eeriksp commented on May 10, 2024

I had the same issue with a Django project.
I created the superuser through manage.py createsuperuser which worked out fine, but when I tried to log in via the web interface, I got the described error.
The reason was that I was using production settings when I ran the server, but development settings when using manage.py. So the superuser was created to the development Sqlite database, while the server tried to access the production Postgres database where no migrations had been performed yet.

In case anybody runs into the same issue:

  1. use manage.py the_command --settings the.real.settings
  2. or set the DJANGO_SETTINGS_MODULE to hold the right settings.

from cookiecutter-django.

mavhungutrezzy avatar mavhungutrezzy commented on May 10, 2024

I encountered the same errors as described in this post, but in my case, the issue was that I was using from django.contrib.auth.models import User instead of from django.contrib.auth import get_user_model. After some investigation, I realized that the cause of the error was related to my custom User model, which I had created by subclassing AbstractUser. Once I made the change to use get_user_model(), the errors were resolved.

from cookiecutter-django.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.