Added 'How do I add database-specific options to my CREATE TABLE statements, such as specifying MyISAM as the table type?' to faq.txt

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3236 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-06-29 03:57:19 +00:00
parent 07687c516e
commit 963d88a809
1 changed files with 43 additions and 24 deletions

View File

@ -411,6 +411,36 @@ Using a ``FileField`` or an ``ImageField`` in a model takes a few steps:
absolute URL to your image in a template with absolute URL to your image in a template with
``{{ object.get_mug_shot_url }}``. ``{{ object.get_mug_shot_url }}``.
Databases and models
====================
How can I see the raw SQL queries Django is running?
----------------------------------------------------
Make sure your Django ``DEBUG`` setting is set to ``True``. Then, just do
this::
>>> from django.db import connection
>>> connection.queries
[{'sql': 'SELECT polls_polls.id,polls_polls.question,polls_polls.pub_date FROM polls_polls',
'time': '0.002'}]
``connection.queries`` is only available if ``DEBUG`` is ``True``. It's a list
of dictionaries in order of query execution. Each dictionary has the following::
``sql`` -- The raw SQL statement
``time`` -- How long the statement took to execute, in seconds.
``connection.queries`` includes all SQL statements -- INSERTs, UPDATES,
SELECTs, etc. Each time your app hits the database, the query will be recorded.
Can I use Django with a pre-existing database?
----------------------------------------------
Yes. See `Integrating with a legacy database`_.
.. _`Integrating with a legacy database`: http://www.djangoproject.com/documentation/legacy_databases/
If I make changes to a model, how do I update the database? If I make changes to a model, how do I update the database?
----------------------------------------------------------- -----------------------------------------------------------
@ -439,35 +469,24 @@ uniqueness at that level. Single-column primary keys are needed for things such
as the admin interface to work; e.g., you need a simple way of being able to as the admin interface to work; e.g., you need a simple way of being able to
specify an object to edit or delete. specify an object to edit or delete.
The database API How do I add database-specific options to my CREATE TABLE statements, such as specifying MyISAM as the table type?
================ ------------------------------------------------------------------------------------------------------------------
How can I see the raw SQL queries Django is running? We try to avoid adding special cases in the Django code to accomodate all the
---------------------------------------------------- database-specific options such as table type, etc. If you'd like to use any of
these options, create an `SQL initial data file`_ that contains ``ALTER TABLE``
statements that do what you want to do. The initial data files are executed in
your database after the ``CREATE TABLE`` statements.
Make sure your Django ``DEBUG`` setting is set to ``True``. Then, just do For example, if you're using MySQL and want your tables to use the MyISAM table
this:: type, create an initial data file and put something like this in it::
>>> from django.db import connection ALTER TABLE myapp_mytable ENGINE=MyISAM;
>>> connection.queries
[{'sql': 'SELECT polls_polls.id,polls_polls.question,polls_polls.pub_date FROM polls_polls',
'time': '0.002'}]
``connection.queries`` is only available if ``DEBUG`` is ``True``. It's a list As explained in the `SQL initial data file`_ documentation, this SQL file can
of dictionaries in order of query execution. Each dictionary has the following:: contain arbitrary SQL, so you can make any sorts of changes you need to make.
``sql`` -- The raw SQL statement .. _SQL initial data file: http://www.djangoproject.com/documentation/model_api/#providing-initial-sql-data
``time`` -- How long the statement took to execute, in seconds.
``connection.queries`` includes all SQL statements -- INSERTs, UPDATES,
SELECTs, etc. Each time your app hits the database, the query will be recorded.
Can I use Django with a pre-existing database?
----------------------------------------------
Yes. See `Integrating with a legacy database`_.
.. _`Integrating with a legacy database`: http://www.djangoproject.com/documentation/legacy_databases/
Why is Django leaking memory? Why is Django leaking memory?
----------------------------- -----------------------------