mirror of
https://github.com/django/django.git
synced 2025-01-03 06:55:47 +00:00
Relocated database setup details to install docs to simplify tutorial 2.
Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
This commit is contained in:
parent
1005c2abd1
commit
82c71f0168
@ -17,48 +17,15 @@ Database setup
|
|||||||
Now, open up :file:`mysite/settings.py`. It's a normal Python module with
|
Now, open up :file:`mysite/settings.py`. It's a normal Python module with
|
||||||
module-level variables representing Django settings.
|
module-level variables representing Django settings.
|
||||||
|
|
||||||
By default, the configuration uses SQLite. If you're new to databases, or
|
By default, the :setting:`DATABASES` configuration uses SQLite. If you're new
|
||||||
you're just interested in trying Django, this is the easiest choice. SQLite is
|
to databases, or you're just interested in trying Django, this is the easiest
|
||||||
included in Python, so you won't need to install anything else to support your
|
choice. SQLite is included in Python, so you won't need to install anything
|
||||||
database. When starting your first real project, however, you may want to use a
|
else to support your database. When starting your first real project, however,
|
||||||
more scalable database like PostgreSQL, to avoid database-switching headaches
|
you may want to use a more scalable database like PostgreSQL, to avoid
|
||||||
down the road.
|
database-switching headaches down the road.
|
||||||
|
|
||||||
If you wish to use another database, install the appropriate :ref:`database
|
If you wish to use another database, see :ref:`details to customize and get
|
||||||
bindings <database-installation>` and change the following keys in the
|
your database running <database-installation>`.
|
||||||
:setting:`DATABASES` ``'default'`` item to match your database connection
|
|
||||||
settings:
|
|
||||||
|
|
||||||
* :setting:`ENGINE <DATABASE-ENGINE>` -- Either
|
|
||||||
``'django.db.backends.sqlite3'``,
|
|
||||||
``'django.db.backends.postgresql'``,
|
|
||||||
``'django.db.backends.mysql'``, or
|
|
||||||
``'django.db.backends.oracle'``. Other backends are :ref:`also available
|
|
||||||
<third-party-notes>`.
|
|
||||||
|
|
||||||
* :setting:`NAME` -- The name of your database. If you're using SQLite, the
|
|
||||||
database will be a file on your computer; in that case, :setting:`NAME`
|
|
||||||
should be the full absolute path, including filename, of that file. The
|
|
||||||
default value, ``BASE_DIR / 'db.sqlite3'``, will store the file in your
|
|
||||||
project directory.
|
|
||||||
|
|
||||||
If you are not using SQLite as your database, additional settings such as
|
|
||||||
:setting:`USER`, :setting:`PASSWORD`, and :setting:`HOST` must be added.
|
|
||||||
For more details, see the reference documentation for :setting:`DATABASES`.
|
|
||||||
|
|
||||||
.. admonition:: For databases other than SQLite
|
|
||||||
|
|
||||||
If you're using a database besides SQLite, make sure you've created a
|
|
||||||
database by this point. Do that with "``CREATE DATABASE database_name;``"
|
|
||||||
within your database's interactive prompt.
|
|
||||||
|
|
||||||
Also make sure that the database user provided in :file:`mysite/settings.py`
|
|
||||||
has "create database" privileges. This allows automatic creation of a
|
|
||||||
:ref:`test database <the-test-database>` which will be needed in a later
|
|
||||||
tutorial.
|
|
||||||
|
|
||||||
If you're using SQLite, you don't need to create anything beforehand - the
|
|
||||||
database file will be created automatically when it is needed.
|
|
||||||
|
|
||||||
While you're editing :file:`mysite/settings.py`, set :setting:`TIME_ZONE` to
|
While you're editing :file:`mysite/settings.py`, set :setting:`TIME_ZONE` to
|
||||||
your time zone.
|
your time zone.
|
||||||
|
@ -76,8 +76,8 @@ In addition to the officially supported databases, there are :ref:`backends
|
|||||||
provided by 3rd parties <third-party-notes>` that allow you to use other
|
provided by 3rd parties <third-party-notes>` that allow you to use other
|
||||||
databases with Django.
|
databases with Django.
|
||||||
|
|
||||||
In addition to a database backend, you'll need to make sure your Python
|
To use another database other than SQLite, you'll need to make sure that the
|
||||||
database bindings are installed.
|
appropriate Python database bindings are installed:
|
||||||
|
|
||||||
* If you're using PostgreSQL, you'll need the `psycopg`_ or `psycopg2`_
|
* If you're using PostgreSQL, you'll need the `psycopg`_ or `psycopg2`_
|
||||||
package. Refer to the :ref:`PostgreSQL notes <postgresql-notes>` for further
|
package. Refer to the :ref:`PostgreSQL notes <postgresql-notes>` for further
|
||||||
@ -97,6 +97,33 @@ database bindings are installed.
|
|||||||
* If you're using an unofficial 3rd party backend, please consult the
|
* If you're using an unofficial 3rd party backend, please consult the
|
||||||
documentation provided for any additional requirements.
|
documentation provided for any additional requirements.
|
||||||
|
|
||||||
|
And ensure that the following keys in the ``'default'`` item of the
|
||||||
|
:setting:`DATABASES` dictionary match your database connection settings:
|
||||||
|
|
||||||
|
* :setting:`ENGINE <DATABASE-ENGINE>` -- Either
|
||||||
|
``'django.db.backends.sqlite3'``,
|
||||||
|
``'django.db.backends.postgresql'``,
|
||||||
|
``'django.db.backends.mysql'``, or
|
||||||
|
``'django.db.backends.oracle'``. Other backends are :ref:`also available
|
||||||
|
<third-party-notes>`.
|
||||||
|
|
||||||
|
* :setting:`NAME` -- The name of your database. If you’re using SQLite, the
|
||||||
|
database will be a file on your computer. In that case, ``NAME`` should be
|
||||||
|
the full absolute path, including the filename of that file. You don’t need
|
||||||
|
to create anything beforehand; the database file will be created
|
||||||
|
automatically when needed. The default value, ``BASE_DIR / 'db.sqlite3'``,
|
||||||
|
will store the file in your project directory.
|
||||||
|
|
||||||
|
.. admonition:: For databases other than SQLite
|
||||||
|
|
||||||
|
If you are not using SQLite as your database, additional settings such as
|
||||||
|
:setting:`USER`, :setting:`PASSWORD`, and :setting:`HOST` must be added.
|
||||||
|
For more details, see the reference documentation for :setting:`DATABASES`.
|
||||||
|
|
||||||
|
Also, make sure that you've created the database by this point. Do that
|
||||||
|
with "``CREATE DATABASE database_name;``" within your database's
|
||||||
|
interactive prompt.
|
||||||
|
|
||||||
If you plan to use Django's ``manage.py migrate`` command to automatically
|
If you plan to use Django's ``manage.py migrate`` command to automatically
|
||||||
create database tables for your models (after first installing Django and
|
create database tables for your models (after first installing Django and
|
||||||
creating a project), you'll need to ensure that Django has permission to create
|
creating a project), you'll need to ensure that Django has permission to create
|
||||||
|
Loading…
Reference in New Issue
Block a user