django项目python manage.py syncdb错误

时间:2015-05-30 06:42:25

标签: python django

我试图在Ubuntu14.04上运行我的Django项目,但是我收到一条错误消息:

我从命令行创建了我的数据库:      root @ ubuntu:〜/ my_blog#mysql -u root -p

 mysql> create database cs01 default charset = utf8;

我的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)") 

1 个答案:

答案 0 :(得分:0)

mysql似乎在抱怨,因为你试图在你的django设置文件中使用空/空密码字段来访问你创建的数据库(以root身份并且可能使用root密码)。我认为您必须将root密码添加到您的设置文件中,或者(如果您在设置中放置root密码时感到不安)丢弃数据库并创建一个新的数据库,其中包含您可以放入的凭据您的设置 - 以便您的mysql数据库设置和您的django DATABASES设置匹配。

如果你这样做并且你的数据库仍然存在权限问题,你可能需要调整你的mysql配置文件;如有必要,应该有足够的在线文档向您展示如何做到这一点。