I get this error while trying to migrate:
SQLSTATE[HY000]: General error: 1005 Can't create table testing.#sql-1848_3ae (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table gallery add constraint gallery_user_id_foreign foreign key (user_id) references users (id))
[PDOException] SQLSTATE[HY000]: General error: 1005 Can't create table testing.#sql-1848_3ae (errno: 150 "Foreign key constraint is incorrectly formed")
here are my migrations:
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
class CreateGalleryTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('gallery', function (Blueprint $table) {
$table->increments('id');
$table->string('description')->nullable();
$table->integer('user_id');
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('gallery');
}
}