I'm following a tutorial that uses Django's authentication system to log in users and when the sqlite3 db is first connected to django and the command python manage.py syncdb (tutorial is from before syncdb was deprecated) is run, I don't get this same message in the command line:
You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now?
I instead ran
python manage.py makemigrations
python manage.py migrate
and this seemed to have set up the tables
but then when I run:
select * from auth_user;
nothing is returned to me in the command line.
How can I setup a superuser from command line and get encrypted password, etc?
Related
I'm trying to deploy a simple django application (SQLite3) to render but I can't log in to the admin page even with valid superuser credentials. I could authenticate locally, but not while on the render deployed version.
Your help is much appreciated!
Try running python manage.py createsuperuser in the Render Shell.
Documentation on creating a Django admin account on Render deployments.
As a substitute to running python manage.py createsuperuser on Render Shell, you can do a quick deployment with python manage.py createsuperuser --no-input on your build script and have environment variables such as DJANGO_SUPERUSER_USERNAME set. You then have to remove this hack for later builds.
See https://stackoverflow.com/a/59467533/4932353 for more information.
I created many test accounts in my heroku server. Now they all have empty columns, and therefore do not work. And now I want to remove all data about existing users/accounts, including superuser, then recreate. How I can do this?
You can go to your terminal, where you have executed the command 'python manage.py runserver' and execute the command - 'python manange.py shell', then your shell will start.
Then execute the command:-
step-1: from django.contrib.auth.models import User
step-2: User.objects.all().delete() # this will delete all the user from your table
step-3: exit() # exit from the shell
step-4: python manage.py createsuperuser # for creating the superuser
This is totally in server side.
Go to your heroku database and reset database from the setting.
after that.
$ heroku run python manage.py makemigrations
$ heroku run python manage.py migrate
Create New Admin ( can be any or the same your existing)
All done, 100% that works for me.
I'm coding a web app with django and now I'm starting to handle users.
I'm trying to do the easy part, just create a new user throught admin interface, but when I try to do it I get a error and I don't find any info about it.
I enter django admin, log in with superuser, go to users, add user.
It only asks for: username and password.
When I submit changes then I get a NOT NULL constraint failed, this:
NOT NULL constraint failed: auth_user.last_login
I revised django documentation, and there it says to create a user like this:
from django.contrib.auth.models import User
user = User.objects.create_user('john', 'lennon#thebeatles.com', 'johnpassword')
So, I open a terminal, and do "./manage.py shell" "import django" "import User" and then I try this code, but fails too, it says:
NameError: name 'User' is not defined
Maybe I've changed something in the first part of the project? I've created models, templates, urls and used /static/ for references to files.
Thanks for your help!
last_login field changed in django 1.8. Just run the migrations
python manage.py migrate
Same issue, Had to run python manage.py migrate --fake and then python manage.py migrate and it worked perfectly.
In the app folder there is migration folder.. remove all files from it just keep pycache folder and init.py
then execute python manage.py migrate and then python manage.py makemigrations ..
simply we are removing the older migrations and migrating them again
I had a django project "demo_project", I ran syncdb command and created tables and saved data. Then I took a copy of this project "demo_project_copy" and ran syncdb command. Now I can't login with previous data which was stored in database(error: invalid credentials). And when I run syncdb on "demo_project" I get error . did syncdb on "demo_project_copy" overwrite the data of "demo_project" ? What happened?
syncdb doesn't overwrite the database data, it just add the database tables that you need for the application you installed in your project. So if you add a new application in the INSTALLED_APPS in the settings.py file and then run syncdb, the command will add the necessary tables, nothing more.
If you are using django 1.7.x you'd better use the migrate command, since django 1.7.x syncdb is deprecated.
Reference for the syncdb command, documentation is very good for django:
https://docs.djangoproject.com/en/1.6/ref/django-admin/#syncdb
How would you run this django command to syncdb with fabric automatically.
python manage.py syncdb --settings="app.settings.test"
if tried to do run, it gets stuck at the "Do you want to create superuser account", can it passed as yes and login information with it.
run('python manage.py syncdb --settings="app.settings.%s"' % name, pty=True)
Add --noinput to the arguments to keep django-admin from prompting:
python manage.py syncdb --settings="app.settings.%s" --noinput
If you have specific credentials that you'd like to preload always, I suspect the simplest way to achieve that would be to create a data dump of the user database from a machine with (just!) the admin account loaded, and then to load that in after syncdb. Alternatively, you could simply leave out the admin account and add it later with manage.py createsuperuser when and if you need to have it.