How to specify specific engine in Laravel 4 migration


Earlier today I needed to set up a specific database engine for a mysql table that wasn't the databases's default. In this instance, the default was INNODB and I needed it to be MyISAM. We could discuss the reasons why I shouldn't use MyISAM but in this instance that's what I needed.

It's fairly straight forward. Take the following example migration block.

'mysql' => array(  
'driver' => 'mysql',  
'host' => 'hostname',  
'database' => 'database\_name',  
'username' => 'username',  
'password' => 'password\_here',  
'charset' => 'utf8',  
'collation' => 'utf8\_unicode\_ci',  
'prefix' => '',  
),

Then just add the engine configuration.

'mysql' => array(  
'engine' => 'MYISAM',  
'driver' => 'mysql',  
'host' => 'hostname',  
'database' => 'database\_name',  
'username' => 'username',  
'password' => 'password\_here',  
'charset' => 'utf8',  
'collation' => 'utf8\_unicode\_ci',  
'prefix' => '',  
),

**UPDATE**
Thanks @unisys12 for the comment. This needed to be updated for the Blueprint code in Laravel.
Your "up" method might look like:

public function up()  
{  
// Create the \`Posts\` table  
Schema::create('posts', function(\$table)  
{  
\$table->increments('id')->unsigned();  
\$table->integer('user\_id')->unsigned();  
\$table->string('title');  
\$table->string('slug');  
\$table->text('content');  
\$table->timestamps();  
});  
}  

In order to add the table type, you'll need to do this:

public function up()  
{  
// Create the \`Posts\` table  
Schema::create('posts', function(\$table)  
{  
\$table->engine = 'MYISAM';  
\$table->increments('id')->unsigned();  
\$table->integer('user\_id')->unsigned();  
\$table->string('title');  
\$table->string('slug');  
\$table->text('content');  
\$table->timestamps();  
});  
}