password authentication failed for user "saleor"
FATAL: password authentication failed for user "saleor"
when migrating the first time
if it's something related to database please someone help me to figure this out
I'm using Postgres as the saleor documentation says but I can't pass this migrations point
I read somewhere I have to create a database called saleor with saleor as a user with password 'saleor' who is a superuser and if that is the solution tell me how to do that
DATABASES = {
"default": dj_database_url.config(default="postgres://postgres:12345#localhost:5432/saleor", conn_max_age=600)
}
Postgres is my username, and 12345 is my password for username i.e postgres and saleor is database name. you can change database name to any. If you did not change username,password, and database name the it takes default one.
Step 1: Remove everything inside migration folder for app, except the init.py file.
Step 2: Delete or Truncate Your Current Database which is 'saleor'
Step 3: Create the initial migrations and generate the database schema using folowing commands
python manage.py makemigrations
python manage.py migrate
Step 4: Now you can Create new Super user using following command
python manage.py createsuperuser
Related
In my environment I'm trying to create a new superuser via python .\manage.py createsuperuser.
However, when I enter the name I get the following error: Error: That username is already taken..
So I check the auth_user table in PgAdmin and I can see there are no entries.
Moreover, the QuerySet is empty when I do the following:
from django.contrib.auth.models import User
superusers = User.objects.filter(is_superuser=True)
superusers
>>> <QuerySet []>
I'm using a managed cloud-hosted PostgreSQL server with the postgresql_psycopg2 client, and have checked that all credentials are correct.
What am I doing incorrectly? I'm using Django 4.1.2.
I am having these ProgrammingErrors occurring on my production server lately. The page which the user is submitting a form at is a UserCreateView and is being redirected to the phone-verification page. The error reads:
Internal Server Error: /phone-verification/
ProgrammingError at /phone-verification/
column quiz_sitting.percent_correct does not exist
LINE 1: ...rrect_questions", "quiz_sitting"."current_score", "quiz_sitt...
^
I am not sure why its looking at quiz_sitting in the database because /phone-verification/ has nothing to do with that. The view for /phone-verification/ looks like this:
#login_required
def phone_verify_check(request):
employee = request.user
phone_verify, _ = PhoneVerify.objects.get_or_create(employee=employee)
login_tracker = EmployeeLogin.objects.create(employee=employee, ip_address=get_client_ip(request))
login_tracker.save()
if phone_verify.verified:
return redirect('dashboard')
else:
return redirect('resend')
I am using Django tenant schemas for handling subdomains which means when I run a migration it looks like:
python manage.py makemigrations
python manage.py migrate_schemas --shared
python manage.py migrate_schemas --tenant
I recently deleted all my migrations because I was having these ProgrammingErrors on another page and then I ran the makemigrations etc again and it seemed to have fix it. But now it is occurring again. I really hope there isn't some sort of corruption in the database like columns being mixed up. Any help is greatly appreciated!
I want to run my custom command from django view which create new user. Here is my command
python manage.py tenant_command createsuperuser --schema=schema_name
Here schema name my be change
Above command is same as
python manage.py createsuperuser
Here i didn't know how to pass username, email and password and confirm password any suggestion would be appreciated
There are two ways to achieve what you trying to do:
Using code to change the user object and save it to database
Calling the command you mentioned
According to django docs you can call your commands in code using call_command function, it takes arguments and pass them to command too:
call_command("custom_command", arguments..)
In the other way you have access to User model in your view so you can import it directly and create the user:
from django.contrib.auth impor get_user_model
get_user_model().objects.create()
I have a Django application that is working perfectly. It's connected to a MySQL server hosted on the cloud.
The MySQL server is set to auto-rotate the password every 30 days for security reasons. Django can access the new password only when settings.py is loaded using a custom function I have developed (that will fetch the new password from AWS Secrets Manager).
I'm looking for a way to allow Django to detect if a connection has a problem then update the password all transparent to the user.
Is that possible?
Options I can think of:
You could use a custom middleware that checks the connection before each request.
You could use a cron job that periodically checks for failed database connections, and updates the settings if it finds such a failure.
To check for connections you can use the method django.db.connection.ensure_connection(). If you look at this answer, you could try something like this:
from django.db import connection
from django.db.utils import OperationalError
class Command(BaseCommand):
def handle(self, *args, **options):
try:
# if this succeeds, no further action is needed
connection.ensure_connection()
except OperationalError:
# update the DB password and try again
I was trying to subclass AbstractUser and stuck in an error on running migrate, and makemigrations says No changes detected
django.db.utils.ProgrammingError: relation "auth_group" does not exist
model:
class SubClient(AbstractUser):
client_id = models.ForeignKey(Client)
phone = models.CharField(max_length=15)
added in settings.py:
AUTH_USER_MODEL = 'myadmin.SubClient'
This error means the auth_group table does not exist in your database. Which means you did not run Django's migration files (python files describing database structure and its changes over time).
As you have your own models, you first need to create migration files for them by running python manage.py makemigrations.
Then run python manage.py migrate to run all migrations (Django's + yours), this will create all database tables (including auth_croup).
Read the doc to lean more about migrations.
when using AbstractUser could i use django's user's builtin password-reset workflow such as password-reset, password-reset-done etc.
the reason i am asking is that i extended user model using AbstractUser but these built-in function not working and i do not get any error but it redirects me to search page and there is no documentation on the internet regarding this issue:
from django.contrib.auth import views as auth_views
path('password-reset/', auth_views.PasswordResetView.as_view(template_name='accounts/password_reset.html'),
name='password-reset'),
path('password-reset/done/',
auth_views.PasswordResetDoneView.as_view(template_name='accounts/password_reset_done.html'),
name='password-reset-done'),
path('password-reset-confirm/<uidb65>/<token>/',
auth_views.PasswordResetConfirmView.as_view(template_name='accounts/password_reset_confirm.html'),
name='password-reset-confirm'),
path('password-reset-complete/s',
auth_views.PasswordResetCompleteView.as_view(template_name='accounts/password_reset_complete.html'),
name='password-reset-complete')