Django

Code

Changeset 3236

Show
Ignore:
Timestamp:
06/28/06 22:57:19 (2 years ago)
Author:
adrian
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/faq.txt

    r3210 r3236  
    412412       ``{{ object.get_mug_shot_url }}``. 
    413413 
     414Databases and models 
     415==================== 
     416 
     417How can I see the raw SQL queries Django is running? 
     418---------------------------------------------------- 
     419 
     420Make sure your Django ``DEBUG`` setting is set to ``True``. Then, just do 
     421this:: 
     422 
     423    >>> from django.db import connection 
     424    >>> connection.queries 
     425    [{'sql': 'SELECT polls_polls.id,polls_polls.question,polls_polls.pub_date FROM polls_polls', 
     426    'time': '0.002'}] 
     427 
     428``connection.queries`` is only available if ``DEBUG`` is ``True``. It's a list 
     429of dictionaries in order of query execution. Each dictionary has the following:: 
     430 
     431    ``sql`` -- The raw SQL statement 
     432    ``time`` -- How long the statement took to execute, in seconds. 
     433 
     434``connection.queries`` includes all SQL statements -- INSERTs, UPDATES, 
     435SELECTs, etc. Each time your app hits the database, the query will be recorded. 
     436 
     437Can I use Django with a pre-existing database? 
     438---------------------------------------------- 
     439 
     440Yes. See `Integrating with a legacy database`_. 
     441 
     442.. _`Integrating with a legacy database`: http://www.djangoproject.com/documentation/legacy_databases/ 
     443 
    414444If I make changes to a model, how do I update the database? 
    415445----------------------------------------------------------- 
     
    440470specify an object to edit or delete. 
    441471 
    442 The database API 
    443 ================ 
    444  
    445 How can I see the raw SQL queries Django is running? 
    446 ---------------------------------------------------- 
    447  
    448 Make sure your Django ``DEBUG`` setting is set to ``True``. Then, just do 
    449 this:: 
    450  
    451     >>> from django.db import connection 
    452     >>> connection.queries 
    453     [{'sql': 'SELECT polls_polls.id,polls_polls.question,polls_polls.pub_date FROM polls_polls', 
    454     'time': '0.002'}] 
    455  
    456 ``connection.queries`` is only available if ``DEBUG`` is ``True``. It's a list 
    457 of dictionaries in order of query execution. Each dictionary has the following:: 
    458  
    459     ``sql`` -- The raw SQL statement 
    460     ``time`` -- How long the statement took to execute, in seconds. 
    461  
    462 ``connection.queries`` includes all SQL statements -- INSERTs, UPDATES, 
    463 SELECTs, etc. Each time your app hits the database, the query will be recorded. 
    464  
    465 Can I use Django with a pre-existing database? 
    466 ---------------------------------------------- 
    467  
    468 Yes. See `Integrating with a legacy database`_. 
    469  
    470 .. _`Integrating with a legacy database`: http://www.djangoproject.com/documentation/legacy_databases/ 
     472How do I add database-specific options to my CREATE TABLE statements, such as specifying MyISAM as the table type? 
     473------------------------------------------------------------------------------------------------------------------ 
     474 
     475We try to avoid adding special cases in the Django code to accomodate all the 
     476database-specific options such as table type, etc. If you'd like to use any of 
     477these options, create an `SQL initial data file`_ that contains ``ALTER TABLE`` 
     478statements that do what you want to do. The initial data files are executed in 
     479your database after the ``CREATE TABLE`` statements. 
     480 
     481For example, if you're using MySQL and want your tables to use the MyISAM table 
     482type, create an initial data file and put something like this in it:: 
     483 
     484    ALTER TABLE myapp_mytable ENGINE=MyISAM; 
     485 
     486As explained in the `SQL initial data file`_ documentation, this SQL file can 
     487contain arbitrary SQL, so you can make any sorts of changes you need to make. 
     488 
     489.. _SQL initial data file: http://www.djangoproject.com/documentation/model_api/#providing-initial-sql-data 
    471490 
    472491Why is Django leaking memory?