Changeset 4749
- Timestamp:
- 03/16/07 10:42:58 (1 year ago)
- Files:
-
- django/trunk/docs/databases.txt (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/databases.txt
r4724 r4749 1 1 =============================== 2 Notes About Supported Databases2 Notes about supported databases 3 3 =============================== 4 4 5 Django attempts to support as many features as possible on all databases. 6 However, since not all database servers are identical, there is obviously 7 going to be some variations. This file describes some of the 8 features that might relevant to Django usage. It is not intended as a 9 replacement for server-specific documentation or reference manuals. 5 Django attempts to support as many features as possible on all database 6 backends. However, not all database backends are alike, and we've had to make 7 design decisions on which features to support and which assumptions we can make 8 safely. 10 9 11 MySQL Notes 10 This file describes some of the features that might be relevant to Django 11 usage. Of course, it is not intended as a replacement for server-specific 12 documentation or reference manuals. 13 14 MySQL notes 12 15 =========== 13 16 14 17 Django expects the database to support transactions, referential integrity, 15 and Unicode support (UTF-8 encoding). Fortunately MySQL_ has all these18 and Unicode support (UTF-8 encoding). Fortunately, MySQL_ has all these 16 19 features as available as far back as 3.23. While it may be possible to use 17 3.23 or 4.0, you will probably have less trouble if you use 4.1 or 5.0.20 3.23 or 4.0, you'll probably have less trouble if you use 4.1 or 5.0. 18 21 19 MySQL -4.122 MySQL 4.1 20 23 --------- 21 24 22 MySQL-4.1_ has greatly improved support for character sets. It is possible to25 `MySQL 4.1`_ has greatly improved support for character sets. It is possible to 23 26 set different default character sets on the database, table, and column. 24 27 Previous versions have only a server-wide character set setting. It's also the 25 28 first version where the character set can be changed on the fly. 4.1 also has 26 support for views, but these are not currently used by Django.29 support for views, but Django currently doesn't use views. 27 30 28 MySQL -5.031 MySQL 5.0 29 32 --------- 30 33 31 MySQL-5.0_ adds the ``information_schema`` database, which contains detailed32 data on all database schema. This is used for Django's ``inspectdb`` feature,33 when it is available. 5.0 also has support for stored procedures, but these 34 are not currently used by Django.34 `MySQL 5.0`_ adds the ``information_schema`` database, which contains detailed 35 data on all database schema. Django's ``inspectdb`` feature uses this 36 ``information_schema`` if it's available. 5.0 also has support for stored 37 procedures, but Django currently doesn't use stored procedures. 35 38 36 39 .. _MySQL: http://www.mysql.com/ 37 .. _MySQL -4.1: http://dev.mysql.com/doc/refman/4.1/en/index.html38 .. _MySQL -5.0: http://dev.mysql.com/doc/refman/5.0/en/index.html40 .. _MySQL 4.1: http://dev.mysql.com/doc/refman/4.1/en/index.html 41 .. _MySQL 5.0: http://dev.mysql.com/doc/refman/5.0/en/index.html 39 42 40 Storage Engines43 Storage engines 41 44 --------------- 42 45 … … 44 47 change the default storage engine in the server configuration. 45 48 46 The default one is MyISAM_. The main drawback of MyISAM is that it does not47 currently have support for transactions or foreign keys. On the plus side, it48 iscurrently the only engine that supports full-text indexing and searching.49 The default engine is MyISAM_. The main drawback of MyISAM is that it doesn't 50 currently support transactions or foreign keys. On the plus side, it's 51 currently the only engine that supports full-text indexing and searching. 49 52 50 53 The InnoDB_ engine is fully transactional and supports foreign key references. 51 54 52 55 The BDB_ engine, like InnoDB, is also fully transactional and supports foreign 53 key references. However, it 's use seems to be somewhatdeprecated.56 key references. However, its use seems to be deprecated. 54 57 55 58 `Other storage engines`_, including SolidDB_ and Falcon_, are on the horizon. … … 67 70 ------- 68 71 69 `MySQLdb`_ is the Python interface to MySQL. 1.2.1 is the first version which70 has support for MySQL -4.1 and newer. If you are trying to use an older version71 of MySQL, then 1.2.0 *m ay* work for you.72 `MySQLdb`_ is the Python interface to MySQL. 1.2.1 is the first version that 73 has support for MySQL 4.1 and newer. If you are trying to use an older version 74 of MySQL, then 1.2.0 *might* work for you. 72 75 73 76 .. _MySQLdb: http://sourceforge.net/projects/mysql-python 74 77 75 78 Creating your database 76 ~~~~~~~~~~~~~~~~~~~~~~ 79 ---------------------- 77 80 78 81 You can `create your database`_ using the command-line tools and this SQL:: 79 82 80 83 CREATE DATABASE <dbname> CHARACTER SET utf8; 81 82 This ensures all tables and columns will use utf8 by default.83 84 85 This ensures all tables and columns will use UTF-8 by default. 86 84 87 .. _create your database: http://dev.mysql.com/doc/refman/5.0/en/create-database.html 85 88 86 89 Connecting to the database 87 ~~~~~~~~~~~~~~~~~~~~~~~~~~ 90 -------------------------- 88 91 89 92 Refer to the `settings documentation`_. … … 107 110 'read_default_file': '/path/to/my.cnf', 108 111 } 109 112 110 113 # my.cnf 111 114 [client] … … 115 118 default-character-set = utf8 116 119 117 There are several other MySQLdb connection options which may be useful, such 118 as ``ssl``, ``use_unicode``, ``init_command``, and ``sql_mode``; consult the120 Several other MySQLdb connection options may be useful, such as ``ssl``, 121 ``use_unicode``, ``init_command``, and ``sql_mode``. Consult the 119 122 `MySQLdb documentation`_ for more details. 120 123 121 124 .. _settings documentation: http://www.djangoproject.com/documentation/settings/#database-engine 122 125 .. _MySQL option file: http://dev.mysql.com/doc/refman/5.0/en/option-files.html … … 124 127 125 128 Creating your tables 126 ~~~~~~~~~~~~~~~~~~~~ 129 -------------------- 127 130 128 When Django generates the schema, it doesn't specify a storage engine, so they129 will be created with whatever default `storage engine`__ your database server 130 is configured for. The easiest solution is to set your database server's default 131 storage engine to the desired engine.131 When Django generates the schema, it doesn't specify a storage engine, so 132 tables will be created with whatever default storage engine your database 133 server is configured for. The easiest solution is to set your database server's 134 default storage engine to the desired engine. 132 135 133 __ `storage engines`_ 134 135 If you are using a hosting service and can't change your server's default 136 If you're using a hosting service and can't change your server's default 136 137 storage engine, you have a couple of options. 137 138 138 After the tables is created, all that is needed to convert it to a new storage 139 engine (such as InnoDB) is:: 140 141 ALTER TABLE <tablename> ENGINE=INNODB; 139 * After the tables are created, execute an ``ALTER TABLE`` statement to 140 convert a table to a new storage engine (such as InnoDB):: 142 141 143 With a lot of tables, this can be tedious. 142 ALTER TABLE <tablename> ENGINE=INNODB; 144 143 145 Another option is to use the ``init_command`` option for MySQLdb prior to 146 creating your tables:: 144 This can be tedious if you have a lot of tables. 147 145 148 DATABASE_OPTIONS = { 149 ... 150 "init_command": "SET storage_engine=INNODB", 151 ... 152 } 146 * Another option is to use the ``init_command`` option for MySQLdb prior to 147 creating your tables:: 153 148 154 This sets the default storage engine upon connecting to the database. After 155 your tables are set up and running in production, you should remove this 156 option. 149 DATABASE_OPTIONS = { 150 # ... 151 "init_command": "SET storage_engine=INNODB", 152 # ... 153 } 157 154 158 Another method for changing the storage engine is described in 159 AlterModelOnSyncDB_. 155 This sets the default storage engine upon connecting to the database. 156 After your tables have been created, you should remove this option. 157 158 * Another method for changing the storage engine is described in 159 AlterModelOnSyncDB_. 160 160 161 161 .. _AlterModelOnSyncDB: http://code.djangoproject.com/wiki/AlterModelOnSyncDB
