错误是:没有名为sqlite3的模块

时间:2015-01-21 11:32:14

标签: python django sqlite

数据库设置为:

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'dataBase',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': 'dataBase',
        'PASSWORD': '',
        'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}

和异常生成:

django.core.exceptions.ImproperlyConfigured: 'django.contrib.gis.db.backends.sqlite3' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
    u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
Error was: No module named sqlite3.base

关注django文档https://docs.djangoproject.com/en/1.7/ref/contrib/gis/tutorial/

2 个答案:

答案 0 :(得分:1)

改变conf。如果您使用的是sqlite(通过这只是为了参考,根据您的需要进行更改,如dbname等)

DATABASES = {
    'default': {
       'NAME': os.path.join(BASE_DIR, 'yourdbname.sqlite'), 
       'ENGINE': 'django.db.backends.sqlite3',

  }
}

这将创建名称为“yourdbname”的数据库,其中您的应用程序settings.py位于此处,您可以参考this link我想它会对您有所帮助

答案 1 :(得分:0)

如果使用sqlite3存储数据,则应更改conf文件,这是一个示例,只需更改db文件位置:

DATABASES = {
    'default': {
        'ENGINE': 'sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': './db.db',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': 'dataBase',
        'PASSWORD': '',
        'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}