14

If you fail to set a database engine in setting.py you get an error.

Is there some way to disable the database portion of django for a specific site if you don't have a need for a database?

Acorn
  • 49,061
  • 27
  • 133
  • 172

4 Answers4

11

You are required to use a database engine if you want to use some features of django, like sessions, for example. If you do not need those, just remove them from middleware classes.

If you want to use sessions or store some data using django apps, but do not want to do all the complicated database configurations, you can use sqlite3 as your database engine. It does not require any setup, all you need is to specify a path, where database file will be created and stored. Thats it:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '/var/www/mysite/sqlite.db',                      # Or path to database file if using sqlite3.
        'USER': '',                      # 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.
    }
}
Silver Light
  • 44,202
  • 36
  • 123
  • 164
  • Useful to know that some other features of django use the database engine! – Acorn Feb 05 '11 at 19:37
  • Thank you Silver Light for your answer. I've followed your instructions and endedup with: "DatabaseError: no such table: django_session". Any ideas? (I'm on Windows 7 btw) – urig May 04 '11 at 08:32
  • @urig, go to your project root and run `python manage.py syncdb` – Silver Light May 04 '11 at 12:57
  • Sessions [can be configured to use a file or the cache instead of the database.](http://www.librador.com/2011/05/23/How-to-run-Django-tests-without-a-database/) but there are other apps that need a DB and would have to be disabled (see above link). As others said here and there, if you don't need a DB/ORM, you might want to pick another framework than Django. – Jérôme Dec 03 '15 at 09:39
5

Can you list a SQLite database there?

Although I would consider, if I were you, if using a heavyweight framework like Django is appropriate for the task you intend it for (because you don't even need a database).

Sri Raghavan
  • 601
  • 1
  • 5
  • 12
  • 2
    I agree. Look for something more lightweight. Django is great but it forces you to conform to its way of thinking. And that includes databases, too. – Santa Feb 05 '11 at 19:27
2

You may need it if using some of the built in db models that Django offers. Here is a microproject that only has the bare minimum to form a response, so no db is prsent:

https://github.com/radzhome/django_microproject

As you can see the settings.py file is pretty stripped down.

radtek
  • 34,210
  • 11
  • 144
  • 111
1

You don't need to do anything. I don't get an error when I don't define a backend.

  1. django-admin.py startproject myproject
  2. open urls.py and map a url to a view.
  3. run the dev server and visit your page.

Bam, django without a database.

Yuji 'Tomita' Tomita
  • 115,817
  • 29
  • 282
  • 245