0 votes

I added this:
enter image description here

I have a Account and a Tag Model and it looks like this:
enter image description here

Migration fails because it looks like this:
enter image description here

Error:

   Symfony\Component\Debug\Exception\FatalThrowableError  : Too few arguments to function Illuminate\Database\Schema\Blueprint::foreign(), 0 passed in /Users/marton/Sites/mBud/database/migrations/2019_11_07_102754_skipper_migrations_2019110710275404.php on line 276 and at least 1 expected
related to an answer for: [Answered] Polymorphic relations
in How To & Manuals by (300 points)
edited by

Thanks for the report. Can you please send me your project? (It's sufficient to send only these three entities).

It's some bug in polymorph export but we\re using similar test-case which works ok. So I would need to see the differences.

Please send it to [email protected]

Thanks

I will sent it, but in my head you can not have a foreignkey in that direction. Since I will have more entities to the Taggable relation.

Even if this is how its supposed to be added:

 $table->foreign('taggable_id')->references('id')->on('accounts');

This will break when you add another taggable entity.

Not sure I understand you. The direction of the MN depends on the order of how you created it.

Skipper can't determine the correct way. It's up to the user to correctly choose the owner and inverse side.

But based on your model I believe the association is created correctly. This is how taggable can looks like for multiple elements:

enter image description here

Can you post how the migration file will look like. Especially where foreignkeys are set.

##File: database/migrations/2019_10_21_162209_skipper_migrations_2019102116220956.php
<?php
/* 
 * Migrations generated by: Skipper (http://www.skipper18.com)
 * Migration id: 057b401d-fb53-4e1f-bc52-90e8a6876c44
 * Migration datetime: 2019-10-21 16:22:09.561807
 */ 

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class SkipperMigrations2019102116220956 extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('tags', function (Blueprint $table) {
            $table->bigInteger('id')->autoIncrement()->unsigned();
        });
        Schema::create('taggable', function (Blueprint $table) {
            $table->('tag_id')->nullable(true);
            $table->bigInteger('taggable_id')->nullable(true)->unsigned();
            $table->string('taggable_type')->nullable(true)->unsigned();
        });
        Schema::create('posts', function (Blueprint $table) {
            $table->bigInteger('id')->autoIncrement()->unsigned();
        });
        Schema::create('videos', function (Blueprint $table) {
            $table->bigInteger('id')->autoIncrement()->unsigned();
        });
        Schema::table('taggable', function (Blueprint $table) {
            $table->foreign('tag_id')->references('id')->on('tags');
            $table->foreign()->references()->on('posts');
        });
        Schema::table('taggable', function (Blueprint $table) {
            $table->foreign('tag_id')->references('id')->on('tags');
            $table->foreign()->references()->on('videos');
        });
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('taggable', function (Blueprint $table) {
            $table->dropForeign('tag_id');
            $table->dropForeign();
        });
        Schema::table('taggable', function (Blueprint $table) {
            $table->dropForeign('tag_id');
            $table->dropForeign();
        });
        Schema::dropIfExists('videos');
        Schema::dropIfExists('posts');
        Schema::dropIfExists('taggable');
        Schema::dropIfExists('tags');
    }
} 

I just noticed it. We have the same issue in our tests too. Someone overlook the missing param!

Ok, we have to definitely check it ;-)

Please log in or register to answer this question.