简体   繁体   English

Django项目python manage.py syncdb错误

[英]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: 我试图在Ubuntu14.04上使我的Django项目正常工作,但出现一条错误消息,内容为:

I created my database from the command line as: root@ubuntu:~/my_blog# mysql -u root -p 我是从命令行创建数据库的:root @ ubuntu:〜/ my_blog#mysql -u root -p

 mysql> create database cs01 default charset = utf8;

My settings.py file contains: 我的settings.py文件包含:

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. mysql似乎在抱怨,因为您尝试使用django设置文件中的空/空白密码字段访问创建的数据库(以root身份,大概使用root密码)。 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. 我认为您必须将root密码添加到您的设置文件中,或者(如果您不愿意将root密码放入设置中,则可以避免)放弃您的数据库,并使用可以在您的设置中放置的凭据创建一个新的数据库-因此您的mysql db设置和django DATABASES设置是否匹配。

If you do this and still have permissions issues with your db, you may have to adjust your mysql config file; 如果执行此操作,但数据库仍然存在权限问题,则可能需要调整mysql配置文件; there should be ample online documentation to show you how to do that, if necessary. 如有必要,应该有足够的在线文档向您展示如何做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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