I am new to django.I am using eclipse IDE and my OS is windows 7.I am trying to use postgre sql.My model page is like this:.My settings page is like this:.When I try to type python manage.py sql Mystudent where Mystudent is my app,It shows operational error:fe_sendauth: no password supplied.So when I entered user name as test and password as password it shows operational error:password authentication failed for user 'test'.Please help me.
You should specify host and port in your settings.py file. If you are running postgresql locally it will be:
'HOST': 'localhost',
'PORT': '5432',
Edit
Also note that mydb.db is not a valid database name for postgres.
Related
I am hosting a postgresql database on AWS using the RDS service. I am trying to connect the django project to the aws database using the settings.py file in the django project. I keep getting the following error:
connection to server at "database-1.xxxxxx.us-east-1.rds.amazonaws.com" (xx.xxx.xx.xxx), port 5432 failed: FATAL: password authentication failed for user "local_user"
This error is unexpected because it should not be trying to authenticate the local_user as this is the user for my local postgres server, it should be trying to authenticate the user for the hosted database, which is completely different.
This is what my settings file looks like:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ.get('DATABASE_NAME'),
'USER': os.environ.get('DATABASE_USER'),
'PASSWORD': os.environ.get('DATABASE_PASSWORD'),
'HOST': "database-1.xxxxxx.us-east-1.rds.amazonaws.com",
'PORT': 5432
}
}
I can't figure out what the issue seems to be. Any help will be appreciated!
I named the environment variable wrong so USER was none!
My Django project fails to connect to postgres database.
django.db.utils.OperationalError: FATAL: password authentication
failed for user "postgres"
The settings.py file:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': '127.0.0.1',
'PORT': 5432,
'ATOMIC_REQUESTS': True
}
}
The pg_hba.conf file contents:
Before, the 'TRUSTED' method was set to 'PEER' by default. By it wasn't working that way. So I changed it to TRUSTED, ran systemctl restart postgresql, and it isn't working now either.
I know that postgres password is empty by default, so I tried the following:
sudo -u postgres psql
postgres=# ALTER USER postgres PASSWORD 'postgres';
The output was ALTER ROLE.
But the error from Django still persists.
I ran out of ideas. Any hints ?
I ran out of ideas.
I would try to use ALTER ROLE instead of alter USER, as described in the docs. But since the response is ALTER ROLE, both might work.
Otherwise, you can try to login directly into the user
sudo psql -d myproject -U myprojectuser
Another option might be to check if a new user would work. I know the error says password authentication but have you granted privileges to the user?
CREATE USER myprojectuser WITH PASSWORD 'password';
ALTER ROLE myprojectuser SET client_encoding TO 'utf8';
ALTER ROLE myprojectuser SET default_transaction_isolation TO 'read committed';
ALTER ROLE myprojectuser SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;
Commands were taken from the digitalocean ubuntu & django & posgres setup guide
Since you specify the host as '127.0.0.1', you will not match either the 'peer' or the 'trust' lines which only apply to local sockets, not TCP connection. But rather the 127.0.0.1/32 md5 line.
Setting the users password should have worked. Look in the server's log file for more detailed reasons it did not.
I'm trying to deploy my django app on pythonanywhere by cloning from my github.
When migrating, I'm getting access denied error followed by (using password:YES),here is the a screenshot of that,
Thanks in advance !!
It seems to me like your database settings are wrong. Your database hostname on PythonAnywhere should look something like yourusername.mysql.pythonanywhere-services.com
Check the Database page in your PythonAnywhere dashboard for the correct settings.
Edit: you must use the hostname, username and password from your dashboard in the Django settings file. The adress 10.0.0.4 indicates that your current settings file does not contain the correct settings.
You should configure your DB settings on yourapp/settings.py as mentioned in pythonanywhere guide
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '<your_username>$<your_database_name>',
'USER': '<your_username>',
'PASSWORD': '<your_mysql_password>',
'HOST': '<your_mysql_hostname>',
}
}
There is also an existing post on SO that might be helpful
I'm trying to learn web development with Django and I was following this guide to do so.
Everything works fine until I run the following:
python manage.py makemigrations
I get this error message:
password authentication failed for user "myprojectuser"
I have checked and rechecked many times and the password is correct in the settings.py file.
Below is the content of the file (settings.py):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'myproject',
'USER': 'myprojectuser',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '',
}
}
I am using postgreSQL 9.5, python 2.7, and Django 1.10.
From your guide:
"
By default, Postgres uses an authentication scheme called "peer authentication" for local connections. Basically, this means that if the user's operating system username matches a valid Postgres username, that user can login with no further authentication.
"
so I am guessing that if you will create a user for your DB with the same name as your OS local username it might work :)
In case the "DATABASES" setting you showed are not the one you actually use - check if the "NAME" and the "USER" are in lowercase
I have been struggling for this issue for the whole days while no solutions at all. so I post it here.
I am trying to set up a blog website in Heroku via Django 1.8 which uses Python 3.4.3. I follows the instructions from Heroku website here.
I use "foreman start" to run Django project in my Mac and I already installed all dependence.
Part of my setting.py file involving the database initially looks like:
import dj_database_url
DATABASES = {}
DATABASES['default'] = dj_database_url.config()
Then I got error: ImproperlyConfigured at /settings.DATABASES is improperly configured. Please supply the ENGINE value.
Then I modify the files by adding one line supplying the ENGINE value:
import dj_database_url
DATABASES = {}
DATABASES['default'] = dj_database_url.config()
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
Based on this post answered by Or Arbel, it should work. But I got another error: ImproperlyConfigured at /settings.DATABASES is improperly configured. Please supply the NAME value.
What should I do next? Actually my Django project is very simple and does not involve any database operations(may need in the future). I just want to make it works on Heroku. Thanks!
Do I need to create a database to continue? I just want to make the webpage works.
Thanks for your guys help, specially souldeux.
Update:
I have fixed the issue by using souldeux's method by providing more informations about the database. Here I want to emphasis that it seems the code from the original Heroku tutorial does not work for Django 1.8:
import dj_database_url ####not working for my case
DATABASES = {}
DATABASES['default'] = dj_database_url.config()
Initially I did not create a database because I think it is not necessary for simple projects, based on my understanding obtained from Heroku tutorial. Actually it does need to create a database in Heroku to make it works. The tutorial is here. You need run "heroku config -s | grep HEROKU_POSTGRESQL" to get the database information. The format is like:
scheme://username:password#host:port/database
So you can get 'database', 'username', 'password', etc.
Afterwards, modify the 'settings.py' according to souldeux, then run following codes:
git add .
git commit -m "Ready to go to Heroku"
git push heroku master
heroku run python manage.py syncdb
Now it works. But other issues arise like my webpages do not show images... Anyway it solved. Please confirm my solutions, thanks.
I think you need to add more information to your database definition. For instance, here's what my own database entry looks like in my settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django',
'USER': 'redacted',
'PASSWORD': 'redacted',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
If you don't have a database user and password to enter in the fields marked redacted then you need to make sure you have the actual database created and psycopg2 installed.