20π
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
112π
./manage.py migrate
If youβve just enabled all the middlewares etc this will run each migration and add the missing tables.
- [Django]-How to show ALL keys through redis-cli?
- [Django]-Remove default apps from Django-admin
- [Django]-How to repeat a "block" in a django template
48π
Only thing you need to do is :
python manage.py migrate
and after that:
python manage.py createsuperuser
after that you can select username and password.
here is the sample output:
Username (leave blank to use 'hp'): admin
Email address: xyz@gmail.com
Password:
Password (again):
Superuser created successfully.
- [Django]-How to send html email with django with dynamic content in it?
- [Django]-Django add extra field to a ModelForm generated from a Model
- [Django]-Django South β table already exists
12π
This will work for django version <1.7:
Initialize the tables with the command
manage.py syncdb
This allows you to nominate a βsuper userβ as well as initializing any tables.
- [Django]-How do i pass GET parameters using django urlresolvers reverse
- [Django]-Optimal architecture for multitenant application on django
- [Django]-Django set field value after a form is initialized
10π
it is need to make migration before create superuser.
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
Username : admin
Password : 12345678
python manage.py runserver
- [Django]-"Failed building wheel for psycopg2" β MacOSX using virtualenv and pip
- [Django]-Paginating the results of a Django forms POST request
- [Django]-Including a querystring in a django.core.urlresolvers reverse() call
7π
Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
try running
python manage.py migrate
then run
python manage.py createsuperuser
- [Django]-Django: Arbitrary number of unnamed urls.py parameters
- [Django]-Forbidden (403) CSRF verification failed. Request aborted. Reason given for failure: Origin checking failed does not match any trusted origins
- [Django]-How does one make logging color in Django/Google App Engine?
6π
For custom forms( if you have made your own forms) use this command to migrate
python manage.py migrate βrun-syncdb
- [Django]-How can I avoid "Using selector: EpollSelector" log message in Django?
- [Django]-How to unit test file upload in django
- [Django]-Django Celery Logging Best Practice
4π
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']
try:
self.Meta.model.objects.get(username=username)
except self.Meta.model.DoesNotExist:
return username
raise forms.ValidationError(
self.error_messages['duplicate_username'],
code='duplicate_username',
)
- [Django]-Get distinct values of Queryset by field
- [Django]-Django, filter by specified month and year in date range
- [Django]-Models.py getting huge, what is the best way to break it up?
3π
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",)
and
python manage.py migrate auth
python manage.py migrate
- [Django]-Best way to make Django's login_required the default
- [Django]-How do I use Django templates without the rest of Django?
- [Django]-Using Cloudfront with Django S3Boto
2π
On Django 1.11 I had to do this after following instructions in docs https://docs.djangoproject.com/en/1.11/topics/auth/customizing/#substituting-a-custom-user-model
# create default database:
./manage.py migrate
# create my custom model migration:
# running `./manage.py makemigrations` was not enough
./manage.py makemigrations books
# specify one-off defaults
# create table with users:
./manage.py migrate
- [Django]-What is the easiest way to clear a database from the CLI with manage.py in Django?
- [Django]-Django unit tests without a db
- [Django]-How to do SELECT COUNT(*) GROUP BY and ORDER BY in Django?
2π
I have no idea what I did wrong but got to the point where I decided to clear the whole database. So I ran the command:
python manage.py flush
After that my database was clear then I ran the commands;
python manage.py makemigrations
python manage.py migrate
then:
python manage.py createsuperuser
That worked for me.
- [Django]-Django Rest framework, how to include '__all__' fields and a related field in ModelSerializer ?
- [Django]-What is the best django model field to use to represent a US dollar amount?
- [Django]-Django migrate βfake and βfake-initial explained
1π
Just do the following flow
$ django-admin createproject <your project name>
under <your project dict>
type django-admin createapp <app name>
under <app name>/admin.py
from django.contrib import admin
from .models import Post
admin.site.register(Post)
Go to the root project. Then $python manage.py migrate
Then it asks for username and password
- [Django]-Django template can't loop defaultdict
- [Django]-Django Admin nested inline
- [Django]-Django Rest Framework pagination extremely slow count
- [Django]-Problems with contenttypes when loading a fixture in Django
- [Django]-Use get_queryset() method or set queryset variable?
- [Django]-Django 1.8: Create initial migrations for existing schema
1π
theres four steps for adding a custom user model to django
- Create a CustomUser model
- update project/settings.py AUTH_USER_MODEL
- customize UserCreationForm & UserChangeForm
- add the custom user model to admin.py
you missed customize forms , add the CustomUser and CustomUserAdmin to admin.site.register() , then makemigrations nd migrate .
#proj_app/forms.py
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',)
#proj_app/admin.py
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',]
admin.site.register(CustomUser, 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
- [Django]-Check permission inside a template in Django
- [Django]-Remove pk field from django serialized objects
- [Django]-Can a dictionary be passed to django models on create?
0π
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 settings.py file where you defined your database setting like this:
DATABASES = {
'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 ;
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/home/django/django_project/db.sqlite3',
}
}
I hope that your problem will resolve now.
- [Django]-What is actually assertEquals in Python?
- [Django]-How to obtain a QuerySet of all rows, with specific fields for each one of them?
- [Django]-Why use Django on Google App Engine?
0π
python manage.py makemigrations then β python manage.py migrate fixes it.
Assuming Apps defined/installed in settings.py exist in the project directory.
- [Django]-Auto-create primary key used when not defining a primary key type warning in Django
- [Django]-How do I create sub-applications in Django?
- [Django]-How does one make logging color in Django/Google App Engine?
0π
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 manage.py runserverβ command.
i hope it will be work fineβ¦.
- [Django]-How to query Case-insensitive data in Django ORM?
- [Django]-In a Django form, how do I make a field readonly (or disabled) so that it cannot be edited?
- [Django]-URL-parameters and logic in Django class-based views (TemplateView)
0π
If You did any changes in project/app then execute:
python manage.py migrate
python manage.py makemigrations
python manage.py createsuperuser
- [Django]-Setting DEBUG = False causes 500 Error
- [Django]-How to print BASE_DIR from settings.py from django app in terminal?
- [Django]-Can't connect to local MySQL server through socket '/tmp/mysql.sock
- [Django]-How to get the name of current app within a template?
- [Django]-Django: "projects" vs "apps"
- [Django]-Silence tqdm's output while running tests or running the code via cron