SQLSTATE[HY000]: General error: 1005 Can't create table - Laravel 4

You must first create the table, then create the foreign keys:

Schema::create('gigs', function($table)
{
    $table->increments('gig_id');

    $table->dateTime('gig_startdate');

    $table->integer('band_id')->unsigned();
    $table->integer('stage_id')->unsigned();
});

Schema::table('gigs', function($table)
{
    $table->foreign('band_id')
        ->references('band_id')->on('bands')
        ->onDelete('cascade');

    $table->foreign('stage_id')
        ->references('stage_id')->on('stages')
        ->onDelete('cascade');
});

And your bands table should migrate first, since the gigs is referencing it.


While this doesn't apply to OP, others might have this issue:

From the bottom of the Laravel Schema docs:

Note: When creating a foreign key that references an incrementing integer, remember to always make the foreign key column unsigned.

You can do this via $table->integer('user_id')->unsigned(); when creating your table in the migration file.

Took me a few minutes to realize what was happening.


For those whom other answers doesn't help, the same error throws also when you try to use 'SET_NULL' action on non-nullable column.