I am trying to connect to the localhost/phpmyadmin through xampp server for my django project. When i type
python manage.py runserver
on my command prompt, i'm getting error.
django.db.utils.OperationalError: (1044, "Access denied for user ''#'localhost' to database 'djangoproject'")
There is no password set on my phpmyadmin, it is just by default user 'root' and password [null]
I have written the below code in my manage.py file to connect to the database page.
DATABASES = {
'default' : {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'djangoproject',
'USER': ' root ',
'PASSWORD': '',
'HOST': 'localhost',
'PORT':''
}
}
There is also this in my phpmyadmin page on the top
A user account allowing any user from localhost to connect is present. This will prevent other users from connecting if the host part of their account allows a connection from any (%) host.
I do not understand what is wrong. I am a beginner in django framework.
Your user does not have an access to the database. Use the commands below to set up your database
DROP DATABASE IF EXISTS `mydb`;
CREATE DATABASE `mydb`
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
USE 'mysql';
GRANT ALL PRIVILEGES ON mydb.* TO 'mydb_user'#'localhost' IDENTIFIED BY 'your_password'
WITH GRANT OPTION;
FLUSH PRIVILEGES;
Related
I am new to Django.i am learning Django for the past few weeks,i have some trouble on changing the databse to sqllite to mysql.
setting.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydb',
'USER': 'root',
'PASSWORD': ' ',
'HOST': 'localhost',
'PORT': '3306',
}}
When i try to run the server using py manage.py runserver
It show me the error like
django.db.utils.OperationalError: (1045, "Access denied for user 'root'#'localhost' (using password: YES)")
SPECIFICATION
python-3.8
django-3
MySQL(xampp)
OS-windows
This is most likely an issue with your USER, PASSWORD or HOST fields. You are probably not providing correct values. Try executing mysql -u root -p -h localhost and enter the password when asked for it. You should get the same error.
My guess is your password is just empty. So delete the space character for password and it should work.
If that is the case, you should really set a password. Refer to this - How to reset or change the MySQL root password?
I have just started learning Django after I took some tutorials for Python.
I am trying to connect my POSTGRES database to the Django project I have just created.
However, I am experiencing this problem:
django.db.utils.OperationalError: FATAL: database "producthuntdb" does not exist
I followed these steps:
1) Opened postgress by clicking its icon
2) Clicked on the database "postgress". The terminal opened and I wrote: CREATE DATABASE producthuntdb; The database has been created because I see it if I open postgress via its icon.
3) Went to my Django project in "settings" and change the SQLITE database to the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'producthuntdb',
'USER': 'mymac2017',
'PASSWORD': 'mypassword',
'HOST': 'localhost',
'PORT': '5432',
}
}
4) Run the code python3 manage.py migrate
However, I am getting the error:
django.db.utils.OperationalError: FATAL: database "producthuntdb" does not exist
So I did the following:
Cliking on postgress icon and opening the the database producthuntdb
Once the terminal is open, I wrote: \du
There are two users with the attributes:
1) mymac2017 | Superuser, Create role, Create DB | {}
2) postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
What am I doing wrong?
I tried to look other answers to this problem and most of the issues are from misspelling the database name OR not creating it. However, the name of my database is correct and I can see the database producthuntdb if I open postgres.
Many thanks for your help.
I set the wrong port of the Database in the Django "settings.py".
I was using 'PORT': '5432' instead of 'PORT': '5433'
SOLUTION:
Go to your Postgres app/icon/program
Click on "Server setting" and see which PORT the database POSTGRES is using
Be sure that the PORT the database is using is the same as the one you write in the "settings.py" of your Django project.
I ve been struggling about figuring out relation between postgre users and linux users and the permissions between them.First question I want to ask is that ,let s assume I have tom linux user and tom postgre user which I created with psql command.What is the relation between those two? The reason I am asking is realated with following question:
I am using vagrant and ubuntu in it.There is 2 userss , first one is Linux "vagrant" user , second one is PostgreSql "vagrant" user which I created through following commands:
CREATE USER vagrant WITH PASSWORD '123.123';
GRANT ALL PRIVILEGES ON DATABASE cashier to vagrant;
which should means and also is that vagrant have all permissions on cashier database.
I should also mention as an aside note that I am using provisioning and vagrant uses root user when executing provisions , so root should also have all permissions on the cashier databse because I am importing dump into cashier database on provisioning.
so you can easily assume root have granted permissions through :
CREATE USER root WITH PASSWORD 'vagrant';
GRANT ALL PRIVILEGES ON DATABASE cashier to root;
Here is the problem: When I try to runserver in django python manage.py runserver
if I go with the following settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'cashier',
'USER': 'vagrant',
'PASSWORD': '123.123',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
I get authentication error, and if I go with the following settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'cashier',
'USER': 'vagrant',
'PASSWORD': 'vagrant',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
Then i have Django:permission denied for relation django_migrations, problem.Simply my question is What is going on?What is the relation between users?Which user should i use ? Why django cant migrate with both user credentials?
Recall :
Linux user vagrant pass vagrant
Postgre user vagrant pass 123.123
Short question - How do I connect to an existing Amazon Web Services MySQL database from my development-stage Django web app?
Context:
I am working on creating a webpage using the Django framework.
I've successfully created an AWS MySQL RDS database and have imported my data and connected to it successfully via MySQL Workbench.
I am now at a point where I am trying to connect to the database from my Django app. I will require read-only functionality from the database from within the app... I will not be writing any new info to the database. Furthermore, I am trying to do this within a development environment, as I am not even close to anything production worthy (ie, I am working locally off of my laptop).
I've added the AWS database information to my Django settings.py file, and based on my research, to generate the requisite models I'll need to utilize Django's 'inspectdb' utility. I've tried that, and the resulting error received was:
django.db.utils.OperationalError: (1045, u"Access denied for user '[my username was here, which actually showed my literal first name rather than any type of username that was established by AWS]'#'pool-[my IP address was here].nwrknj.fios.verizon.net'
Has anyone else experienced this issue and identified a solution?
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'[removed]': {
'NAME': '[removed]',
'ENGINE': 'django.db.backends.mysql',
'USERNAME': '[removed]',
'PASSWORD': '[removed]',
'HOST': '[removed].us-west-2.rds.amazonaws.com',
'PORT': '3306'
Unless you have DATABASE_ROUTERS set to use an alternate database, everything in Django will use the default database. Get rid of the current ENGINE and NAME in default and move all the [removed] db info into default.
Also make sure that the AWS RDS port 3306 is open to your FIOS IP address. Ideally you would restrict it in AWS to only the actual servers (whether on AWS or elsewhere) but for now you may have to set a broad IP range to allow for your FIOS IP changing periodically during development.
I have been working on a Django app locally and it's now time to deploy it to a staging machine.
My Postgres database on the staging machine has a different username and password to my local machine.
I have got the Django app running okay on the remote machine, except that the database has not been initialised.
I assume that I should do this with migrate, so I try running:
$ python manage.py migrate
But I see the following error:
django.db.utils.OperationalError: FATAL: no pg_hba.conf entry
for host "127.0.0.1", user "mylocalusername", database "mylocaldbname"
It's failing because it doesn't allow me to log in with mylocalusername.
I assume that mylocalusername etc must be coming from the migrations files? Certainly the local username isn't set anywhere else on the staging machine, either in my settings file, or on the actual database itself.
How can I set up this database on the staging server?
I guess one way would be to delete everything in migrations and create a new local migration. Is that what I need to do?
I thought migrations were supposed to checked into source code, though, so I'd rather not delete all of them. Also, I want to carry on working on locally and updating my staging and production machines, so I need to find a sustainable way of doing this.
"mylocalusername" comes from settings.py file.
It should looks like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mylocaldbname', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'mylocalusername',
'PASSWORD': 'password',
'HOST': 'localhost', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
You can change it or create a valid user in your postgres database.