2015-05-30 65 views
1

我試圖讓我的Django項目工作,在Ubuntu14.04,但我得到的是一條錯誤信息:Django項目的python manage.py執行syncdb錯誤

我創建了數據庫中的命令行: 根@ Ubuntu的:〜/ my_blog#的mysql -u根-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. 


[email protected]:~/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)") 
+0

你能用命令行用mysql打開這個數據庫嗎--user = root cs01? –

回答

0

MySQL的似乎是在抱怨,因爲您要訪問d b您在django設置文件中創建了一個空白/空白密碼字段(作爲root用戶,並且可能使用root密碼)。我認爲你必須將root密碼添加到你的設置文件中,或者(如果你把root密碼置於設置中可能會感到不自在),請將你的db添加到你的數據庫中,並創建一個新的密碼,這樣你就可以在你的設置中放置 - 你的mysql數據庫設置和你的django DATABASES設置相匹配。

如果你這樣做,仍然有你的數據庫的權限問題,你可能需要調整你的MySQL配置文件;如果有必要,應該有充足的在線文檔向你展示如何做到這一點。

相關問題