DatabaseError python manage.py syncdb

时间:2013-11-17 20:13:00

标签: python mysql django

我正在学习django框架,我遇到django的问题当你启动syncdb时 请帮帮我,如何纠正错误?

使用过的文件

settings.py

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

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)

urls.py

from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'testsite.views.home', name='home'),
    # url(r'^testsite/', include('testsite.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
)

root@lhackg:~/testsite# python manage.py syncdb
Creating tables ...
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
Creating table django_site
Creating table django_admin_log


DatabaseError: (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")

1 个答案:

答案 0 :(得分:1)

作为上述@ karthikr评论的延伸,the ticket regarding this issue已被修复"并关闭 - 虽然你会注意到修复只是文档中的一个变化,承认将Django移植到Python 3的问题。

此时您有2个现实选项:

  1. 使用Python 2.x并继续使用MySql。
  2. 使用Python 3.x并更改数据库后端。