简体   繁体   中英

django project python manage.py syncdb error

I am attempting to get my Django project working, on Ubuntu14.04,but I get an error message that reads:

I created my database from the command line as: root@ubuntu:~/my_blog# mysql -u root -p

 mysql> create database cs01 default charset = utf8;

My settings.py file contains:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
    'NAME': 'cs01',                      # Or path to database file if using sqlite3.
    'USER': 'root',                      # Not used with sqlite3.
    'PASSWORD': '',                  # Not used with sqlite3.
    'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
    'PORT': '',                      # Set to empty string for default. Not used with sqlite3.


root@ubuntu:~/my_blog# 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 443, in        execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-    packages/django/core/management/__init__.py", line 382, 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 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 231, in execute
self.validate()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 103, in get_validation_errors
connection.validation.validate_field(e, opts, f)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/validation.py", line 14, in validate_field
db_version = self.connection.get_server_version()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 415, in get_server_version
self.cursor().close()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 317, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 387, in _cursor
self.connection = Database.connect(**kwargs)
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)
_mysql_exceptions.OperationalError: (1045, "Access denied for user       'root'@'localhost' (using password: NO)") 

mysql seems to be complaining because you are trying to access the db you created (as root and presumably with the root password) with an empty/blank password field in your django settings file. I think you'll have to either add the root password to your settings file or (if you're understandably uneasy with placing your root password in settings) ditch your db and create a new one with credentials you can place in your settings - so that your mysql db settings and your django DATABASES setting match.

If you do this and still have permissions issues with your db, you may have to adjust your mysql config file; there should be ample online documentation to show you how to do that, if necessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM