jskfan
asked on
Django Migrate error
Django Migrate error
I have the settings.py with Databases section configured as below:
When I run the command : python manage.py migrate
I get this output :
I have the settings.py with Databases section configured as below:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'Mydjangoproject',
'HOST': '',
'PORT': '',
'USER': 'root',
'PASSWORD': '123456',
}
}
When I run the command : python manage.py migrate
I get this output :
(py1) C:\Python-Projects\Mydjangoproject>python manage.py migrate
Traceback (most recent call last):
File "C:\Users\user\Envs\py1\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
self.connect()
File "C:\Users\user\Envs\py1\lib\site-packages\django\db\backends\base\base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\user\Envs\py1\lib\site-packages\django\db\backends\mysql\base.py", line 227, in get_new_connection
return Database.connect(**conn_params)
File "C:\Users\user\Envs\py1\lib\site-packages\MySQLdb\__init__.py", line 84, in Connect
return Connection(*args, **kwargs)
File "C:\Users\user\Envs\py1\lib\site-packages\MySQLdb\connections.py", line 179, in __init__
super(Connection, self).__init__(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\user\Envs\py1\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\user\Envs\py1\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\user\Envs\py1\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\user\Envs\py1\lib\site-packages\django\core\management\base.py", line 361, in execute
self.check()
File "C:\Users\user\Envs\py1\lib\site-packages\django\core\management\base.py", line 387, in check
all_issues = self._run_checks(
File "C:\Users\user\Envs\py1\lib\site-packages\django\core\management\commands\migrate.py", line 64, in _run_checks
issues = run_checks(tags=[Tags.database])
File "C:\Users\user\Envs\py1\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\user\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\user\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\user\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\user\Envs\py1\lib\site-packages\django\db\backends\base\base.py", line 256, in cursor
return self._cursor()
File "C:\Users\user\Envs\py1\lib\site-packages\django\db\backends\base\base.py", line 233, in _cursor
self.ensure_connection()
File "C:\Users\user\Envs\py1\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
self.connect()
File "C:\Users\user\Envs\py1\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\user\Envs\py1\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
self.connect()
File "C:\Users\user\Envs\py1\lib\site-packages\django\db\backends\base\base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\user\Envs\py1\lib\site-packages\django\db\backends\mysql\base.py", line 227, in get_new_connection
return Database.connect(**conn_params)
File "C:\Users\user\Envs\py1\lib\site-packages\MySQLdb\__init__.py", line 84, in Connect
return Connection(*args, **kwargs)
File "C:\Users\user\Envs\py1\lib\site-packages\MySQLdb\connections.py", line 179, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")
(py1) C:\Python-Projects\Mydjangoproject>
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
You type that in the same cmd window in which you typed
Does the window freeze or do you just get a windows prompt?
You should have got something like this just with newever versions (I copied this from an old django bug as I don't have the combination windows + mysql)
If the dbshell command doesn't freeze. but just does nothing, then it doesn't help diagnosing your problem (perhaps it's just mysql.exe which is missing on your PC)
Let's try then following (It might work without migrations and indicate whether the db connection works or not)
Then within the shell type:
manage.py migrate
?Does the window freeze or do you just get a windows prompt?
c:\yourpath>
You should have got something like this just with newever versions (I copied this from an old django bug as I don't have the combination windows + mysql)
C:\project>manage.py dbshell
Welcome to the MySQL monitor. Commands end with ; or \
g.
Your MySQL connection id is 6902
Server version: 5.0.51a-community-nt-log MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
If the dbshell command doesn't freeze. but just does nothing, then it doesn't help diagnosing your problem (perhaps it's just mysql.exe which is missing on your PC)
Let's try then following (It might work without migrations and indicate whether the db connection works or not)
manage.py shell
Then within the shell type:
from django.db import connection
cursor = connection.cursor()
cursor.execute("SELECT 1 + 1 as two")
cursor.fetchall()
and tell me if you get any error message.
ASKER
OK this means you created a database named djangoproject. It doesn't indicate whether your credentials int the djangoconfig are correct.
The information visibile in this question suggests, that the database configuration might not be correct. so that's what I'd concentrate on until there's other elements indicating the problem is something else.
Please answer all of my following questions in order to avoid too many iterations.
Q1: can you install a mysql command line client on your machine?
Q1a: if yes, can you connect to your data base with the command line client.
Q2: What do you see if you type my previously suggested commands in the django management.py shell?
Q3: Is the django server located on the same server than phpmyadmin?
Q4: if it is, then you could try to replace "localhost" in the django settings with "127.0.0.1" or vice versa and retry
The information visibile in this question suggests, that the database configuration might not be correct. so that's what I'd concentrate on until there's other elements indicating the problem is something else.
Please answer all of my following questions in order to avoid too many iterations.
Q1: can you install a mysql command line client on your machine?
Q1a: if yes, can you connect to your data base with the command line client.
Q2: What do you see if you type my previously suggested commands in the django management.py shell?
Q3: Is the django server located on the same server than phpmyadmin?
Q4: if it is, then you could try to replace "localhost" in the django settings with "127.0.0.1" or vice versa and retry
ASKER
Q1: can you install a mysql command line client on your machine?
How do you install it ?
Q3: Is the django server located on the same server than phpmyadmin?
all in the same computer
How do you install it ?
Q3: Is the django server located on the same server than phpmyadmin?
all in the same computer
Normally if you install mysql on windows (e.g. from https://dev.mysql.com/downloads/installer/ ) You should have somehwere an executable called `mysql.exe`
I don't use windows that often, so I don't know whether it will be in the search path or whether you have to call it with its absolute path name.
if you found this command line client you should be able to call it with
or with
or with
I don't use windows that often, so I don't know whether it will be in the search path or whether you have to call it with its absolute path name.
if you found this command line client you should be able to call it with
mysql.exe dbname
or with
mysql.exe --user=user_name --password db_name
or with
mysql.exe --user=user_name --password --host=hostname db_name
ASKER
Mysql should show in Services.msc console with other services... but it is not showing
ASKER
I will get back to this topic sometime when I use Django Lab
Thank you
Thank you
ASKER
Open in new window
it does not give any output