SOLVED: I was using USERNAME, not USER from previously attempting Postgres driver.
I'm trying to connect my django project to an RDS MySQL database. I can connect fine using my credentials in MySQL Workbench and mysql command line.
I've set the AWS Security Group and VPC Security Group with
All traffic | All | All | 0.0.0.0/0
Let's say my credentials are
User: abc
Password: password
When I run python manage.py migrate it is attempting to login with Mike, not abc for some unknown reason (Mike is the Windows User). How do I prevent this? Attached is my settings.py:
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'playercomp',
'USERNAME': 'abc',
'PASSWORD': 'password',
'HOST': 'xxx.xxx.us-west-2.rds.amazonaws.com',
'PORT': '3306',
}
}
manage.py
#!/usr/bin/env python
try:
import pymysql
pymysql.install_as_MySQLdb()
except ImportError:
print "Failed to import pymysql"
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "playercomp.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)
Error Trace:
Traceback (most recent call last):
File "manage.py", line 27, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\core\management\__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\core\management\base.py", line 342, in execute
self.check()
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\core\management\base.py", line 374, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\core\management\commands\migrate.py", line 61, in _run_checks
issues = run_checks(tags=[Tags.database])
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\core\checks\database.py", line 10, in check_database_backends
issues.extend(conn.validation.check(**kwargs))
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\db\backends\mysql\validation.py", line 9, in check
issues.extend(self._check_sql_mode(**kwargs))
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\db\backends\mysql\validation.py", line 13, in _check_sql_mode
with self.connection.cursor() as cursor:
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\db\backends\base\base.py", line 231, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\db\backends\base\base.py", line 204, in _cursor
self.ensure_connection()
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\db\backends\base\base.py", line 199, in ensure_connection
self.connect()
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\db\utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\db\backends\base\base.py", line 199, in ensure_connection
self.connect()
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\db\backends\base\base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\db\backends\mysql\base.py", line 263, in get_new_connection
conn = Database.connect(**conn_params)
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\pymysql\__init__.py", line 90, in Connect
return Connection(*args, **kwargs)
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\pymysql\connections.py", line 688, in __init__
self.connect()
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\pymysql\connections.py", line 906, in connect
self._request_authentication()
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\pymysql\connections.py", line 1114, in _request_authentication
auth_packet = self._read_packet()
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\pymysql\connections.py", line 981, in _read_packet
packet.check_error()
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\pymysql\connections.py", line 393, in check_error
err.raise_mysql_exception(self._data)
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\pymysql\err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
django.db.utils.OperationalError: (1045, u"Access denied for user 'Mike'#'host-yy-yy.zzz.zz.com' (using password: YES)")
I added a field 'USER': 'abc' to the DATABASES default, and that worked.
Related
I am trying to do python manage.py migrate to do migrations for my django app but i keep getting this error even though i have supplied the db name, user, password in settings.py.
Any help will be appreciated.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'accountant',
'USER': 'json',
'PASSWORD': '******',
'HOST': 'localhost',
'PORT': '5432'
}
}
Full stacktrace:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute()
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/core/management/__init__.py", line 346, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/core/management/base.py", line 394, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/core/management/base.py", line 445, in execute
output = self.handle(*args, **options)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 93, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/migrations/executor.py", line 19, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/migrations/loader.py", line 47, in __init__
self.build_graph()
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/migrations/loader.py", line 191, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
self.ensure_schema()
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/backends/base/base.py", line 162, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/backends/base/base.py", line 135, in _cursor
self.ensure_connection()
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
self.connect()
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/utils.py", line 98, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
self.connect()
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/backends/base/base.py", line 119, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 176, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: fe_sendauth: no password supplied
I had a problem with my vagrant boxes with ports and everything so I did something that I suspect is inhibiting my ability to run ./manage.py migrate. Here's what it looks like when I run vagrant ssh-config
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/brock1hj/projects/sodium/to-vagrant/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
Here is the full error:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 93, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/migrations/executor.py", line 19, in __init__
self.loader = MigrationLoader(self.connection)
File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/migrations/loader.py", line 47, in __init__
self.build_graph()
File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/migrations/loader.py", line 180, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
self.ensure_schema()
File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/backends/base/base.py", line 162, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/backends/base/base.py", line 135, in _cursor
self.ensure_connection()
File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
self.connect()
File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
self.connect()
File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/backends/base/base.py", line 119, in connect
self.connection = self.get_new_connection(conn_params)
File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 176, in get_new_connection
connection = Database.connect(**conn_params)
File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: FATAL: password authentication failed for user "vagrant"
I'm really not sure what's going on and I think somehow the password for the user "vagrant" somehow got changed from the default "vagrant".
I am using Django 1.8.2
Here is my settings.py file for databases:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'vagrant',
'USER': 'vagrant',
'PASSWORD': 'vagrant',
'HOST': '127.0.0.1',
'PORT': '',
}
}
I feel like it is going to try putting "vagrant" as a password but that is no longer the case.
Trying to enter the dbshell, was prompted to enter the password to ensure "vagrant" didn't work and got:
Password for user vagrant:
psql: error: could not connect to server: could not initiate GSSAPI security context: Unspecified GSS failure.
Minor code may provide more information could not initiate GSSAPI security context: Configuration file does
not specify default realm
FATAL: password authentication failed for user "vagrant"
Try:
vagrant ssh
psql
Then follow instructions on https://www.postgresql.org/docs/9.6/sql-alterrole.html, looks like you want ALTER ROLE vagrant PASSWORD 'vagrant';
I am new to django, I was running the command
python manage.py migrate
and got this error.
(py1) G:\django\djangoproject1>python manage.py migrate Traceback
(most recent call last): File "manage.py", line 22, in
execute_from_command_line(sys.argv) File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\core\management__init__.py",
line 364, in execute_from_command_line
utility.execute() File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\core\management__init__.py",
line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\core\management\base.py",
line 283, in run_from_argv
self.execute(*args, **cmd_options) File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\core\management\base.py",
line 327, in execute
self.check() File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\core\management\base.py",
line 359, in check
include_deployment_checks=include_deployment_checks, File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\core\management\commands\migrate.py",
line 61, in _run_checks
issues = run_checks(tags=[Tags.database]) File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\core\checks\registry.py",
line 81, in run_checks
new_errors = check(app_configs=app_configs) File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\core\checks\database.py",
line 10, in check_database_backends
issues.extend(conn.validation.check(**kwargs)) File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\db\backends\mysql\validation.py",
line 9, in check
issues.extend(self._check_sql_mode(**kwargs)) File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\db\backends\mysql\validation.py",
line 13, in _check_sql_mode
with self.connection.cursor() as cursor: File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\db\backends\base\base.py",
line 254, in cursor
return self._cursor() File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\db\backends\base\base.py",
line 229, in _cursor
self.ensure_connection() File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\db\backends\base\base.py",
line 213, in ensure_connection
self.connect() File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\db\utils.py", line
94, in exit
six.reraise(dj_exc_type, dj_exc_value, traceback) File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\db\backends\base\base.py",
line 213, in ensure_connection
self.connect() File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\db\backends\base\base.py",
line 189, in connect
self.connection = self.get_new_connection(conn_params) File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\db\backends\mysql\base.py",
line 274, in get_new_connection
conn = Database.connect(**conn_params) File "C:\Users\Mahin\Envs\py1\lib\site-packages\MySQLdb__init__.py", line
84, in Connect
return Connection(*args, **kwargs) File "C:\Users\Mahin\Envs\py1\lib\site-packages\MySQLdb\connections.py",
line 164, in init
super(Connection, self).init(*args, **kwargs2) django.db.utils.OperationalError: (1045, "Access denied for user
'root'#'localhost' (using password: YES)")
Since I should have magically known your settings.py DB config and my post was deleted for not answering the question without "requiring clarification from the asker" I'm reposting to try and help. The default password for root user in a mysql db is "", that is its left blank. Right now there is a mismatch between your db and the configuration you provided in your settings.py file. Go into your dbms and make sure that the setting for the database match the ones you provided in your settings.py.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'DB NAME',
'USER': 'USER NAME',
'PASSWORD':'USER PW',
'HOST' : 'localhost',
}
}
If these match to your db you should be able to now migrate.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'djangomypro',
'USER': 'root',
'PASSWORD': '123456',
'HOST': 'localhost',
'PORT': ''
}
}
This is my configuration.
After running python manage.py migrate in terminal, I get the following result.
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "manage.py", line 15, in
execute_from_command_line(sys.argv) File "/home/vishal/anaconda3/lib/python3.6/site-packages/django/core/management/init.py",
line 381, in execute_from_command_line
utility.execute() File "/home/vishal/anaconda3/lib/python3.6/site-packages/django/core/management/init.py",
line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/vishal/anaconda3/lib/python3.6/site-packages/django/core/management/base.py",
line 316, in run_from_argv
self.execute(*args, **cmd_options) File "/home/vishal/anaconda3/lib/python3.6/site-packages/django/core/management/base.py",
line 350, in execute
self.check() File "/home/vishal/anaconda3/lib/python3.6/site-packages/django/core/management/base.py",
line 379, in check
include_deployment_checks=include_deployment_checks, File "/home/vishal/anaconda3/lib/python3.6/site-packages/django/core/management/commands/migrate.py",
line 59, in _run_checks
issues = run_checks(tags=[Tags.database]) File "/home/vishal/anaconda3/lib/python3.6/site-packages/django/core/checks/registry.py",
line 71, in run_checks
new_errors = check(app_configs=app_configs) File "/home/vishal/anaconda3/lib/python3.6/site-packages/django/core/checks/database.py",
line 10, in check_database_backends
issues.extend(conn.validation.check(**kwargs)) File "/home/vishal/anaconda3/lib/python3.6/site-packages/django/db/backends/mysql/validation.py",
line 9, in check
issues.extend(self._check_sql_mode(**kwargs)) File "/home/vishal/anaconda3/lib/python3.6/site-packages/django/db/backends/mysql/validation.py",
line 13, in _check_sql_mode
with self.connection.cursor() as cursor: File "/home/vishal/anaconda3/lib/python3.6/site-packages/django/db/backends/base/base.py",
line 255, in cursor
return self._cursor() File "/home/vishal/anaconda3/lib/python3.6/site-packages/django/db/backends/base/base.py",
line 232, in _cursor
self.ensure_connection() File "/home/vishal/anaconda3/lib/python3.6/site-packages/django/db/backends/base/base.py",
line 216, in ensure_connection
self.connect() File "/home/vishal/anaconda3/lib/python3.6/site-packages/django/db/utils.py",
line 89, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value File "/home/vishal/anaconda3/lib/python3.6/site-packages/django/db/backends/base/base.py",
line 216, in ensure_connection
self.connect() File "/home/vishal/anaconda3/lib/python3.6/site-packages/django/db/backends/base/base.py",
line 194, in connect
self.connection = self.get_new_connection(conn_params) File "/home/vishal/anaconda3/lib/python3.6/site-packages/django/db/backends/mysql/base.py",
line 227, in get_new_connection
return Database.connect(**conn_params) File "/home/vishal/anaconda3/lib/python3.6/site-packages/pymysql/init.py",
line 94, in Connect
return Connection(*args, **kwargs) File "/home/vishal/anaconda3/lib/python3.6/site-packages/pymysql/connections.py",
line 327, in init
self.connect() File "/home/vishal/anaconda3/lib/python3.6/site-packages/pymysql/connections.py",
line 598, in connect
self._request_authentication() File "/home/vishal/anaconda3/lib/python3.6/site-packages/pymysql/connections.py",
line 862, in _request_authentication
auth_packet = self._process_auth(plugin_name, auth_packet) File "/home/vishal/anaconda3/lib/python3.6/site-packages/pymysql/connections.py",
line 933, in _process_auth
pkt = self._read_packet() File "/home/vishal/anaconda3/lib/python3.6/site-packages/pymysql/connections.py",
line 683, in _read_packet
packet.check_error() File "/home/vishal/anaconda3/lib/python3.6/site-packages/pymysql/protocol.py",
line 220, in check_error
err.raise_mysql_exception(self._data) File "/home/vishal/anaconda3/lib/python3.6/site-packages/pymysql/err.py",
line 109, in raise_mysql_exception
raise errorclass(errno, errval) django.db.utils.OperationalError: (1045, "Access denied for user 'root'#'localhost' (using password:
YES)")
looks like django is not able to connect to your database. can you verify if your able to connect using a database client. you can use MYSQLWorkbench to verify this. try logging in with the same parameters you've set for django. I'm not sure but you should be able to see mysql running in your task manager.
you can also try this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'djangomypro',
'USER': 'root',
'PASSWORD': '123456',
'HOST': 'localhost',
'PORT': '3306'
}
}
django.db.utils.OperationalError: (1045, "Access denied for user 'root'#'localhost' (using password: YES)")
when I am trying to connect MySQL to python Django framework for accessing the database,and running the command python manage.py syncdb ,I get following errors. I have created database name mysite and changed into setting like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mysite',
'USER':'root',
'PASSWORD':'sobita1',
'HOST':'',
'PORT':'',
}
}
Traceback:
python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 415, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.7/dist- packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
cursor = connection.cursor()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 160, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 132, in _cursor
self.ensure_connection()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 127, in ensure_connection
self.connect()
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 127, in ensure_connection
self.connect()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 115, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 435, in get_new_connection
conn = Database.connect(**conn_params)
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (1045, "Access denied for user 'root'#'localhost' (using password: YES)")
I had a similar error:
super(Connection, self).init(*args, **kwargs2)
django.db.utils.OperationalError: (1045, "Access denied for user 'root'#'localhost' (using password: YES)")
To solve it:
1) I removed the Password that I gave, but again I got error like this:
File "C:\Users\Rooman\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\mysql\operations.py", line 146, in last_executed_query
query = query.encode(errors='replace')
AttributeError: 'bytes' object has no attribute 'encode'
2) In the operations.py use decode instead of encode
query = query.decode(errors='replace')
3) Finally run the commands:
python manage.py makemigrations
python manage.py migrate
python manage.py runserver
you are providing a wrong username or password for the database