Joined November 2013
·
Adam
Software and Web Developer at Pierce County Community Newspaper Group
·
Tacoma, Washington
·
Posted to
Creating Foreign Keys via Laravel Migration
over 1 year
ago
In the above example, what table is the last bit of code in? It all looks as if it's just referencing itself.
My understanding is it should be:
Schema::create('users',function(Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('user_id');
}
Schema::create('user_profiles', function(Blueprint $table) {
$table->foreign('user_fk_id')->references('id')->on('users');
}
However, this just doesn't make sense as the unsignedInteger('user_id'); is never referenced.
@rizwaniqbal
Thanks so much for the clarification. I was struggling with this for a few days and it really helped.