10

How to force django to use MYISAM storage engine when creating database using syncdb command? This page does not help much to shed light in this issue.

MYISAM is the perfect choice since the database is almost only used for reading and MYISAM is significantly faster that InnoDB. There are still some models.ForeignKey fields in the model, but they are only being used to create master detail admin pages. There is not need of having the actual foreign keys in the database.

bman
  • 5,016
  • 4
  • 36
  • 69

2 Answers2

14

See this page. Using an OPTIONS variable in your DATABASES setting should do the trick, but migrating an existing database to a new engine isn't so easy (think you'd have to re-initialize).

DATABASES = { 
  'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': '',                      
    'USER': '',     
    'PASSWORD': '',
    'OPTIONS': {
           "init_command": "SET storage_engine=MYISAM",
    }   
  }   
}
Community
  • 1
  • 1
Ian Price
  • 7,416
  • 2
  • 23
  • 34
  • 1
    A hint on migrating an existing db: you'll probably want to dump to something like yaml, and import that back in after you recreate the schema. – WhyNotHugo Apr 28 '15 at 06:45
  • 1
    Should use `default_storage_engine` instead of `storage_engine` for mysql 5.7+ – Walty Yeung Sep 18 '17 at 09:00
-1

You should set the storage engine as INNODB in the database definition directly, like this.

DATABASES = {
   'default': {
       'ENGINE': 'django.db.backends.mysql',
       .....
       'STORAGE_ENGINE': 'MYISAM'
   }
}

For New Version you can use:

DATABASES = {
       'default': {
           'ENGINE': 'django.db.backends.mysql',
           .....
           'OPTIONS': {
                     "init_command": "SET storage_engine=MYISAM",
                      } 
       }
    }
Yogesh dwivedi Geitpl
  • 4,252
  • 2
  • 20
  • 34