2013-08-25 107 views
3

对不起,这种愚蠢的问题。我是Django的noob。我在下面的Django官方教程,并在python3 manage.py执行syncdb的阶段,我得到这个巨大的错误Django的错误manage.py syncdb

Creating tables ... 
Creating table django_admin_log 
Creating table auth_permission 
Creating table auth_group_permissions 
Creating table auth_group 
Creating table auth_user_groups 
Creating table auth_user_user_permissions 
Creating table auth_user 
Creating table django_content_type 
Creating table django_session 
Traceback (most recent call last): 
    File "/usr/local/lib/python3.3/dist-packages/django/contrib/contenttypes/models.py", line 39, in get_for_model 
    ct = self._get_from_cache(opts) 
    File "/usr/local/lib/python3.3/dist-packages/django/contrib/contenttypes/models.py", line 29, in _get_from_cache 
    return self.__class__._cache[self.db][key] 
KeyError: 'default' 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "/usr/local/lib/python3.3/dist-packages/django/db/backends/util.py", line 46, in execute 
    return self.cursor.execute(sql, params) 
    File "/usr/local/lib/python3.3/dist-packages/django/db/backends/mysql/base.py", line 124, in execute 
    return self.cursor.execute(query, args) 
    File "/usr/local/lib/python3.3/dist-packages/MySQL_python-1.2.3-py3.3-linux-x86_64.egg/MySQLdb/cursors.py", line 184, in execute 
    self.errorhandler(self, exc, value) 
    File "/usr/local/lib/python3.3/dist-packages/MySQL_python-1.2.3-py3.3-linux-x86_64.egg/MySQLdb/connections.py", line 37, in defaulterrorhandler 
    raise errorvalue 
    File "/usr/local/lib/python3.3/dist-packages/MySQL_python-1.2.3-py3.3-linux-x86_64.egg/MySQLdb/cursors.py", line 171, in execute 
    r = self._query(query) 
    File "/usr/local/lib/python3.3/dist-packages/MySQL_python-1.2.3-py3.3-linux-x86_64.egg/MySQLdb/cursors.py", line 330, in _query 
    rowcount = self._do_query(q) 
    File "/usr/local/lib/python3.3/dist-packages/MySQL_python-1.2.3-py3.3-linux-x86_64.egg/MySQLdb/cursors.py", line 294, in _do_query 
    db.query(q) 
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s AND `django_content_type`.`app_label` = %s)' at line 1") 

The above exception was the direct cause of the following exception: 

Traceback (most recent call last): 
    File "manage.py", line 10, in <module> 
    execute_from_command_line(sys.argv) 
    File "/usr/local/lib/python3.3/dist-packages/django/core/management/__init__.py", line 397, in execute_from_command_line 
    utility.execute() 
    File "/usr/local/lib/python3.3/dist-packages/django/core/management/__init__.py", line 390, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "/usr/local/lib/python3.3/dist-packages/django/core/management/base.py", line 240, in run_from_argv 
    self.execute(*args, **options.__dict__) 
    File "/usr/local/lib/python3.3/dist-packages/django/core/management/base.py", line 283, in execute 
    output = self.handle(*args, **options) 
    File "/usr/local/lib/python3.3/dist-packages/django/core/management/base.py", line 413, in handle 
    return self.handle_noargs(**options) 
    File "/usr/local/lib/python3.3/dist-packages/django/core/management/commands/syncdb.py", line 112, in handle_noargs 
    emit_post_sync_signal(created_models, verbosity, interactive, db) 
    File "/usr/local/lib/python3.3/dist-packages/django/core/management/sql.py", line 216, in emit_post_sync_signal 
    interactive=interactive, db=db) 
    File "/usr/local/lib/python3.3/dist-packages/django/dispatch/dispatcher.py", line 182, in send 
    response = receiver(signal=self, sender=sender, **named) 
    File "/usr/local/lib/python3.3/dist-packages/django/contrib/auth/management/__init__.py", line 82, in create_permissions 
    ctype = ContentType.objects.db_manager(db).get_for_model(klass) 
    File "/usr/local/lib/python3.3/dist-packages/django/contrib/contenttypes/models.py", line 47, in get_for_model 
    defaults = {'name': smart_text(opts.verbose_name_raw)}, 
    File "/usr/local/lib/python3.3/dist-packages/django/db/models/manager.py", line 154, in get_or_create 
    return self.get_queryset().get_or_create(**kwargs) 
    File "/usr/local/lib/python3.3/dist-packages/django/db/models/query.py", line 373, in get_or_create 
    return self.get(**lookup), False 
    File "/usr/local/lib/python3.3/dist-packages/django/db/models/query.py", line 301, in get 
    num = len(clone) 
    File "/usr/local/lib/python3.3/dist-packages/django/db/models/query.py", line 77, in __len__ 
    self._fetch_all() 
    File "/usr/local/lib/python3.3/dist-packages/django/db/models/query.py", line 856, in _fetch_all 
    self._result_cache = list(self.iterator()) 
    File "/usr/local/lib/python3.3/dist-packages/django/db/models/query.py", line 220, in iterator 
    for row in compiler.results_iter(): 
    File "/usr/local/lib/python3.3/dist-packages/django/db/models/sql/compiler.py", line 711, in results_iter 
    for rows in self.execute_sql(MULTI): 
    File "/usr/local/lib/python3.3/dist-packages/django/db/models/sql/compiler.py", line 777, in execute_sql 
    cursor.execute(sql, params) 
    File "/usr/local/lib/python3.3/dist-packages/django/db/backends/util.py", line 46, in execute 
    return self.cursor.execute(sql, params) 
    File "/usr/local/lib/python3.3/dist-packages/django/db/utils.py", line 99, in __exit__ 
    six.reraise(dj_exc_type, dj_exc_value, traceback) 
    File "/usr/local/lib/python3.3/dist-packages/django/utils/six.py", line 328, in reraise 
    raise value.with_traceback(tb) 
    File "/usr/local/lib/python3.3/dist-packages/django/db/backends/util.py", line 46, in execute 
    return self.cursor.execute(sql, params) 
    File "/usr/local/lib/python3.3/dist-packages/django/db/backends/mysql/base.py", line 124, in execute 
    return self.cursor.execute(query, args) 
    File "/usr/local/lib/python3.3/dist-packages/MySQL_python-1.2.3-py3.3-linux-x86_64.egg/MySQLdb/cursors.py", line 184, in execute 
    self.errorhandler(self, exc, value) 
    File "/usr/local/lib/python3.3/dist-packages/MySQL_python-1.2.3-py3.3-linux-x86_64.egg/MySQLdb/connections.py", line 37, in defaulterrorhandler 
    raise errorvalue 
    File "/usr/local/lib/python3.3/dist-packages/MySQL_python-1.2.3-py3.3-linux-x86_64.egg/MySQLdb/cursors.py", line 171, in execute 
    r = self._query(query) 
    File "/usr/local/lib/python3.3/dist-packages/MySQL_python-1.2.3-py3.3-linux-x86_64.egg/MySQLdb/cursors.py", line 330, in _query 
    rowcount = self._do_query(q) 
    File "/usr/local/lib/python3.3/dist-packages/MySQL_python-1.2.3-py3.3-linux-x86_64.egg/MySQLdb/cursors.py", line 294, in _do_query 
    db.query(q) 
django.db.utils.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s AND `django_content_type`.`app_label` = %s)' at line 1") 

我已成功安装python3,MySQL驱动。使用Ubuntu。 这里是我的setings.py

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.mysql', 
     'NAME' : 'blog', 
     'USER' : 'root', 
     'PASSWORD' : 'hellyeah', 
     'HOST' : '', 
     'PORT' : '' 
    } 
} 

这将是真棒,如果有人教我什么是错..

+2

MySQL-python不支持Python 3.3 http://stackoverflow.com/questions/15202503/how-can-i-use-mysql-with-python-3-3-and-django-1-5。官方网页上说,支持是在路上http://sourceforge.net/projects/mysql-python/ –

+0

Owh,谢谢..现在看来我试图学习python没什么... 更好的我回去php – ddiipp

+0

@ user2665252呃,什么?他所说的只是该库与Python 3不兼容。使用Python 2.7代替,或者找到与3.3版兼容的MySQL库。 –

回答

0

这是因为你使用Python 3和Django。目前没有驱动程序可用。既然你从django和Python开始,为什么不使用Sqlite呢,它有一个很好的Python3驱动程序,并且足以满足你的学习体验。

你也可以尝试使用Postgres,但是与Sqlite相比,它的设置要多得多。

+0

作为此更新,您可以使用mysqlclient作为连接器,它应该可以工作:https://pypi.python.org/pypi/mysqlclient – Dennis

相关问题