mirror of
https://github.com/django/django.git
synced 2025-07-24 05:36:15 +00:00
Added sqlite3 database backend -- somewhat tested, but probably not 100% perfect.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@288 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
dbfb35b542
commit
e320a0936e
4 changed files with 202 additions and 41 deletions
|
@ -144,8 +144,8 @@ own lightweight development server. For a production environment, we recommend
|
|||
`Apache 2`_ and mod_python_, although Django follows the WSGI_ spec, which
|
||||
means it can run on a variety of server platforms.
|
||||
|
||||
You'll also need a database engine. PostgreSQL_ is recommended, and MySQL_ is
|
||||
supported.
|
||||
You'll also need a database engine. PostgreSQL_ is recommended, and MySQL_
|
||||
and `SQLite 3`_ are supported.
|
||||
|
||||
.. _Python: http://www.python.org/
|
||||
.. _Apache 2: http://httpd.apache.org/
|
||||
|
@ -153,6 +153,7 @@ supported.
|
|||
.. _WSGI: http://www.python.org/peps/pep-0333.html
|
||||
.. _PostgreSQL: http://www.postgresql.org/
|
||||
.. _MySQL: http://www.mysql.com/
|
||||
.. _`SQLite 3`: http://www.sqlite.org/
|
||||
|
||||
Do I have to use mod_python?
|
||||
----------------------------
|
||||
|
|
|
@ -49,23 +49,27 @@ settings. Let's look at what ``startproject`` created::
|
|||
First, edit ``myproject/settings/main.py``. It's a normal Python module with
|
||||
module-level variables representing Django settings. Edit the file and change
|
||||
these settings to match your database's connection parameters:
|
||||
|
||||
* ``DATABASE_ENGINE`` -- Either 'postgresql', 'mysql' or 'sqlite3'.
|
||||
More coming soon.
|
||||
* ``DATABASE_NAME`` -- The name of your database, or the full path to
|
||||
the database file if using sqlite.
|
||||
* ``DATABASE_USER`` -- Your database username (not used for sqlite).
|
||||
* ``DATABASE_PASSWORD`` -- Your database password (not used for sqlite).
|
||||
* ``DATABASE_HOST`` -- The host your database is on. Leave this as an
|
||||
empty string if your database server is on the same physical machine
|
||||
(not used for sqlite).
|
||||
|
||||
* ``DATABASE_ENGINE`` -- Either 'postgresql' or 'mysql'. More coming soon.
|
||||
* ``DATABASE_NAME`` -- The name of your database.
|
||||
* ``DATABASE_USER`` -- Your database username.
|
||||
* ``DATABASE_PASSWORD`` -- Your database password.
|
||||
* ``DATABASE_HOST`` -- The host your database is on. Leave this as an
|
||||
empty string if your database server is on the same physical machine
|
||||
(localhost).
|
||||
.. admonition:: Note
|
||||
|
||||
(Make sure you've created a database within PostgreSQL or MySQL by this point.
|
||||
Do that with "``CREATE DATABASE database_name;``" within your database's
|
||||
interactive prompt.)
|
||||
Make sure you've created a database within PostgreSQL or MySQL by this
|
||||
point. Do that with "``CREATE DATABASE database_name;``" within your
|
||||
database's interactive prompt.
|
||||
|
||||
Also, note that MySQL support is a recent development, and Django hasn't been
|
||||
comprehensively tested with that database. If you find any bugs in Django's
|
||||
MySQL bindings, please file them in `Django's ticket system`_ so we can fix them
|
||||
immediately.
|
||||
Also, note that MySQL and sqlite support is a recent development, and Django
|
||||
hasn't been comprehensively tested with either database. If you find any
|
||||
bugs in those bindings, please file them in `Django's ticket system`_ so we
|
||||
can fix them immediately.
|
||||
|
||||
Now, take a second to make sure ``myproject`` is on your Python path. You
|
||||
can do this by copying ``myproject`` to Python's ``site-packages`` directory,
|
||||
|
@ -90,8 +94,9 @@ On Windows, you'd use ``set`` instead::
|
|||
|
||||
If you don't see any errors after running ``django-admin.py init``, you know it
|
||||
worked. That command initialized your database with Django's core database
|
||||
tables. If you're interested, run the PostgreSQL or MySQL command-line client
|
||||
and type "\\dt" (PostgreSQL) or "SHOW TABLES;" (MySQL) to display the tables.
|
||||
tables. If you're interested, run the command-line client for your database and
|
||||
type ``\\dt`` (PostgreSQL), ``SHOW TABLES;`` (MySQL), or ``.schema`` (SQLite) to
|
||||
display the tables.
|
||||
|
||||
Now you're set to start doing work. You won't have to take care of this boring
|
||||
administrative stuff again.
|
||||
|
@ -235,27 +240,34 @@ You should see the following (the CREATE TABLE SQL statements for the polls app)
|
|||
|
||||
Note the following:
|
||||
|
||||
* Table names are automatically generated by combining the name of the app
|
||||
(polls) with a plural version of the object name (polls and choices). (You
|
||||
can override this behavior.)
|
||||
* Primary keys (IDs) are added automatically. (You can override this, too.)
|
||||
* The foreign key relationship is made explicit by a ``REFERENCES`` statement.
|
||||
* It's tailored to the database you're using, so database-specific field types
|
||||
such as ``auto_increment`` (MySQL) vs. ``serial`` (PostgreSQL) are handled
|
||||
for you automatically. The author of this tutorial runs PostgreSQL, so the
|
||||
example output is in PostgreSQL syntax.
|
||||
* Table names are automatically generated by combining the name of the app
|
||||
(polls) with a plural version of the object name (polls and choices). (You
|
||||
can override this behavior.)
|
||||
|
||||
* Primary keys (IDs) are added automatically. (You can override this, too.)
|
||||
|
||||
* The foreign key relationship is made explicit by a ``REFERENCES`` statement.
|
||||
|
||||
* It's tailored to the database you're using, so database-specific field types
|
||||
such as ``auto_increment`` (MySQL), ``serial`` (PostgreSQL), or ``integer
|
||||
primary key`` (SQLite) are handled for you automatically. The author of
|
||||
this tutorial runs PostgreSQL, so the example output is in PostgreSQL
|
||||
syntax.
|
||||
|
||||
If you're interested, also run the following commands:
|
||||
|
||||
* ``django-admin.py sqlinitialdata polls`` -- Outputs the initial-data inserts
|
||||
required for Django's admin framework.
|
||||
* ``django-admin.py sqlclear polls`` -- Outputs the necessary ``DROP TABLE``
|
||||
statements for this app, according to which tables already exist in your
|
||||
database (if any).
|
||||
* ``django-admin.py sqlindexes polls`` -- Outputs the ``CREATE INDEX``
|
||||
statements for this app.
|
||||
* ``django-admin.py sqlall polls`` -- A combination of 'sql' and
|
||||
'sqlinitialdata'.
|
||||
* ``django-admin.py sqlinitialdata polls`` -- Outputs the initial-data
|
||||
inserts required for Django's admin framework.
|
||||
|
||||
* ``django-admin.py sqlclear polls`` -- Outputs the necessary ``DROP
|
||||
TABLE`` statements for this app, according to which tables already exist
|
||||
in your database (if any).
|
||||
|
||||
* ``django-admin.py sqlindexes polls`` -- Outputs the ``CREATE INDEX``
|
||||
statements for this app.
|
||||
|
||||
* ``django-admin.py sqlall polls`` -- A combination of 'sql' and
|
||||
'sqlinitialdata'.
|
||||
|
||||
Looking at the output of those commands can help you understand what's actually
|
||||
happening under the hood.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue