[Fixed] How to create/edit composite foreign key ?

+1 vote
asked Jul 21, 2020 in Solved by jin (130 points)
recategorized Aug 14, 2020 by ludek.vodicka

I can make composite foreign key (foreign key with multiple column) by create project from a migrated database, but i cannot find away to create a new one in skipper

2 Answers

+1 vote
answered Jul 21, 2020 by ludek.vodicka Skipper developer (140,450 points)

Simply create two or more primary keys in the target entity and create an association to this entity. Skipper automatically creates composite FK.

commented Aug 13, 2020 by target (130 points)

I have same problem as jin:
Skipper generate migrations in laravel 6x as:

Schema::table('vendors', function (Blueprint $table) {
        $table->foreign('customer_cd', 'customer_sub_cd')->references('customer_cd', 'customer_sub_cd')->on('customers')->onDelete('NO ACTION')->onUpdate('NO ACTION');
    });

Instead of correct must be:

Schema::table('vendors', function (Blueprint $table) {
        $table->foreign(['customer_cd', 'customer_sub_cd'])->references(['customer_cd', 'customer_sub_cd'])->on('customers')->...
commented Aug 13, 2020 by ludek.vodicka Skipper developer (140,450 points)

Please try our latest version from here https://www.skipper18.com/support/402/downloads-skipper-beta

We're currently greatly improving Laravel migration exports. In case any of these fixes will not work, please send me your project to [email protected] so we can test it here.

Thank you

+1 vote
answered Aug 14, 2020 by ludek.vodicka Skipper developer (140,450 points)

Issues with composite foreign keys are fixed in latest beta 3.2.25.1691.

  • Laravel support for associations to non-primary fields (New!) (support-ticket)
  • Laravel support for associations to composite non-primary fields (New!) (support-ticket)
  • Fixed Laravel migration for creating new composite association (support-ticket)

https://www.skipper18.com/support/402/downloads-skipper-beta

commented Aug 14, 2020 by target (130 points)

Thank Ludek for support quickly
Skipper beta servion 3.2.25.1691 resolved the problem for me.

...