如何使用Django项目设置SQLite

如何使用Django项目设置SQLite

本文介绍了如何使用Django项目设置SQLite?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了Django文档(参考,),但是我仍然遇到问题,设置一个Django项目来处理数据库。因为我是Web开发的新手,我想我将从SQLite开始,因为我没有把任何东西投入生产,并没有太多的数据库经验。 (我会很好的从MySQL或PostgreSQL开始。)



在我的Django项目文件夹中,我知道我需要编辑settings.py文件夹来指定数据库其他一些事情问题是,当我在终端中运行 python manage.py syncdb 时,会失败,并显示以下消息:

  django.core.exceptions.ImproperlyConfigured:加载pysqlite2 
或sqlite3模块时出错(按该顺序尝试):没有名为_sqlite3的模块
/ pre>

我假设我的一部分问题是我从源代码安装了Python(2.7)(在),但是我的终端可能默认默认安装在Ubuntu上。或者我想这可能是因为从源代码构建的Python(2.7)不是与SQLite相关联的。或者我想这可能是我需要在DTDABESES中的NAME项目下的settings.py中指定一个SQLite文件,尽管我确信这不是SQLite所必需的。



谁能识别罪魁祸首?我将如何解决这个问题作为一个长期的解决方案(即有什么办法可以消除在Ubuntu上有两个共存的Python安装的含糊不清?)最重要的是,我需要做些什么来建立一个工作的数据库?

解决方案

执行sudo apt-get install libsqlite3-dev,然后重新编译Python 2.7。



从长远来看,为了减少共存的Python安装和软件包的含糊不清,我强烈建议您安装pip,virtualenv和virtualenvwrapper。


I have read the Django documentation (For reference, https://docs.djangoproject.com/en/1.3/intro/tutorial01/), but I'm still having issues setting up a Django project to work with a database. Because I'm new to web development, I figured I would start with SQLite for development since I'm not putting anything into production yet and don't have much experience with databases. (I would be fine starting with MySQL or PostgreSQL though.)

In my Django project folder, I know I need to edit the settings.py folder to specify the database and a few other things. The problem is that when I run python manage.py syncdb in terminal, it fails with this message:

django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2
or sqlite3 modules (tried in that order): No module named _sqlite3

I am assuming part of my problem is that I installed Python (2.7) from source code (explained in-depth in How would I build python myself from source code on Ubuntu?), yet my terminal is probably defaulting to the Python installed by default on Ubuntu. Or I suppose it could be that the Python (2.7) I built from source code somehow wasn't linked to SQLite. Or I suppose it could be that I need to specify an SQLite file in settings.py under the NAME item in DATABASES, although I'm pretty sure that isn't necessary for SQLite.

Can anyone identify the culprit? How would I remedy this as a long-term solution (i.e. Is there any way I can remove the ambiguity of having two co-existing Python installations on Ubuntu?) Most importantly, what do I need to do to set up a working database?

解决方案

Do a 'sudo apt-get install libsqlite3-dev' and then recompile Python 2.7.

In the long term, to reduce ambiguity of co-existing Python installations and packages, I highly recommend installing pip, virtualenv, and virtualenvwrapper.

这篇关于如何使用Django项目设置SQLite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 07:31