'OPTIONS': {
'autocommit': True,
}
This is database-level autocommit
This functionality is not the same as the autocommit decorator. That decorator is a Django-level implementation that commits automatically after data changing operations. The feature enabled using the OPTIONS option provides autocommit behavior at the database adapter level. It commits after every operation.
[1] | Unless this was changed by the packager of your MySQL package. We’ve had reports that the Windows Community Server installer sets up InnoDB as the default storage engine, for example. |
Примечание
If you see ImportError: cannot import name ImmutableSet when trying to use Django, your MySQLdb installation may contain an outdated sets.py file that conflicts with the built-in module of the same name from Python 2.4 and later. To fix this, verify that you have installed MySQLdb version 1.2.1p2 or newer, then delete the sets.py file in the MySQLdb directory that was left by an earlier version.
CREATE DATABASE <dbname> CHARACTER SET utf8;
# settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': '/path/to/my.cnf',
},
}
}
# my.cnf
[client]
database = NAME
user = USER
password = PASSWORD
default-character-set = utf8
After the tables are created, execute an ALTER TABLE statement to convert a table to a new storage engine (such as InnoDB):
ALTER TABLE <tablename> ENGINE=INNODB;
This can be tedious if you have a lot of tables.
Another option is to use the init_command option for MySQLdb prior to creating your tables:
'OPTIONS': {
'init_command': 'SET storage_engine=INNODB',
}
This sets the default storage engine upon connecting to the database. After your tables have been created, you should remove this option.
Another method for changing the storage engine is described in AlterModelOnSyncDB.
Switching to another database backend. At a certain point SQLite becomes too “lite” for real-world applications, and these sorts of concurrency errors indicate you’ve reached that point.
Rewriting your code to reduce concurrency and ensure that database transactions are short-lived.
Increase the default timeout value by setting the timeout database option option:
'OPTIONS': {
# ...
'timeout': 20,
# ...
}
This will simply make SQLite wait a bit longer before throwing “database is locked” errors; it won’t really do anything to solve them.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'xe',
'USER': 'a_user',
'PASSWORD': 'a_password',
'HOST': '',
'PORT': '',
}
}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'xe',
'USER': 'a_user',
'PASSWORD': 'a_password',
'HOST': 'dbprod01ned.mycompany.com',
'PORT': '1540',
}
}
'OPTIONS': {
'threaded': True,
},
'OPTIONS': {
'use_returning_into': False,
},
Aug 21, 2013