I'm a newbie to laravel and migrations, and I can't seem to figure out the correct way to set up a foreign key.
Schema::create('sights', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->text('description');
$table->integer('contact_id');
$table->integer('media_id');
$table->timestamps();
});
Schema::table('sights', function($table) {
$table->foreign('contact_id')->references('id')->on('contacts');
$table->foreign('media_id')->references('sight_id')->on('sightMedia');
});
If it's not clear, "contact_id" is a foreign key that's supposed to reference the column "id" in the table called "contacts", and "media_id" references the column "sight_id" in the intermediary table "sightMedia".
The error it gives me when I try to migrate is the following:
EDIT: This is the users table, it's second in the line of migrations so I suppose that's where the migrations stop and report an error.
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('email');
$table->string('firstName');
$table->string('lastName');
$table->string('password');
$table->string('facebook');
$table->integer('score_id')->unsigned();
$table->integer('role_id')->unsigned();
$table->timestamps();
});
Schema::table('users', function ($table) {
$table->foreign('score_id')->references('id')->on('scores');
$table->foreign('role_id')->references('id')->on('roles');
});
Thank you in advance.