Well, I have multiple databases in django project. One is default
and second istest_dev
. i have created docker container. and then everything went well till building the container. after that When I try to call my django app api which is using test_dev
db for reading data. I have encountered:
OperationalError at /api/projects/
(1045, "Access denied for user 'test_dev'@'xxx.xxx.xxx.xxx' (using password: YES)")
In settings file, my databases configuration:
{
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': Path(__file__).resolve().parent.parent / 'db.sqlite3',
},
"test_dev" : {
'ENGINE': 'django.db.backends.mysql',
'NAME': "test",
'USER': 'test_dev',
'PASSWORD': 'db_password',
'HOST': '?=hosted_domain',
'PORT': '3306',
'SSL': True
}
}
If you know any solution. Please help me out of this. Soon I have to put things on production..
3
Answers
Well I solved my problem by changing the engine. I replaced the following line:
with :
this code solve my current error but after this i have face an other error that i solve by editing
requirements.txt
file:to :
This is an issue with database access privileges. Either the password is wrong, the user was not granted permissions to the specific database or table that you need, or the Django container’s IP address does not match the one bound to the user.
The following SQL:
I believe that while creating the database for the container, your user has not get the desired permissions, to give permissions use the below snippet.
In your terminal:
password is: password (default)
After that,
show databases;
anduse test_dev;
Now, you can check grants by using
show grants;
command, since the user for all hosts does not have any permissions (or maybe there is no user at all), so use the below command to give privileges: