Version 1 (modified by dnozay, 4 years ago) (diff)

management.py trick for innodb storage_engine with mysql.

As discussed in the documentation(1):

  • After syncdb, execute an ALTER TABLE statement to convert tables
    ALTER TABLE <tablename> ENGINE=INNODB;
    
  • or, change settings to use the init_command option for MySQLdb:
    # settings.py
    DATABASES = {
        'default': {
             'OPTIONS': {
                 # works because South changes table creation
                 'init_command': 'SET storage_engine=INNODB',
             }
        }
    }
    
  • or, use post_syncdb trick listed in wiki:AlterModelOnSyncDB,
  • or, create a management.py file along with your app, with:
    # management.py
    from django.db import connection
    # syncdb does "import_module('.management', app_name)"
    # IOW, this gets executed before creating the tables.
    connection.cursor().execute('SET storage_engine=InnoDB;')
    
  • or, if you use South(2) for migrations, with:
    # settings.py
    DATABASES = {
        'default': {
            'STORAGE_ENGINE': 'INNODB'
        }
    }
    
  • or, if you can, edit my.cnf
    # my.cnf
    default-storage-engine=InnoDB
    
Back to Top