Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explicitly set MySQL table storage engine using South and Django

Tags:

I'm running into an issue that South creates the DB table for a new model as INNODB when I migrate but creates the table as MYISAM when another developer runs their own migration.

The problem with this is that all my other tables are MYISAM so using the new tables leads to many foreign key constraint errors.

How can I explicitly make sure the table is created using MYISAM?

What could be causing the table to be created using a different storage engine in different environments?

like image 425
Eron Villarreal Avatar asked Mar 11 '11 06:03

Eron Villarreal


People also ask

Which storage engine is best in MySQL?

Storage engines are MySQL components that handle the SQL operations for different table types. InnoDB is the default and most general-purpose storage engine, and Oracle recommends using it for tables except for specialized use cases. (The CREATE TABLE statement in MySQL 8.0 creates InnoDB tables by default.)

Where is storage engine for table in MySQL?

To determine which engine a database table is currently using, type the following command at the mysql> prompt. Replace database with the name of the database that you want to check: Copy SELECT TABLE_NAME, ENGINE FROM information_schema. TABLES where TABLE_SCHEMA = 'database';

What are the most common storage engines for MySQL?

There are two types of storage engines in MySQL: transactional and non-transactional. For MySQL 5.5 and later, the default storage engine is InnoDB. The default storage engine for MySQL prior to version 5.5 was MyISAM.


1 Answers

To be sure that all migrations are always done using INNODB, you should set the storage engine as INNODB in the database definition directly, like this :

DATABASES = {
    'default': {
        ...
        'OPTIONS'  : { 'init_command' : 'SET storage_engine=INNODB', },
    }

If you are using MySQL 5.7.x and above,

DATABASES = {
    'default': {
        ...
        'OPTIONS'  : { 'init_command' : 'SET default_storage_engine=INNODB', },
    }

But you should know that it can have a performance hit. So you may want to set this option only when running migrations.

like image 58
Xixi Avatar answered Nov 07 '22 19:11

Xixi