How to create laravel migration for tables with multiple foreign keys?












0















I want to create a table with multiple foreign keys. Here is the sql:



CREATE TABLE `customers` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) DEFAULT NULL,
`address` varchar(100) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
`type_id` tinyint(3) unsigned DEFAULT NULL,
`district_id` tinyint(3) unsigned DEFAULT NULL,
`city_id` tinyint(3) unsigned DEFAULT NULL,
`business_id` tinyint(3) unsigned DEFAULT NULL,
`group_id` tinyint(3) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK_customer_1` (`district_id`,`city_id`),
KEY `FK_customer_2` (`business_id`),
KEY `FK_customer_3` (`group_id`),
KEY `FK_customer_4` (`type_id`),
CONSTRAINT `FK_customer_1` FOREIGN KEY (`district_id`, `city_id`)
REFERENCES `cities` (`district_id`, `city_id`) ON DELETE CASCADE,
CONSTRAINT `FK_customer_2` FOREIGN KEY (`business_id`) REFERENCES `businesses` (`business_id`) ON DELETE CASCADE,
CONSTRAINT `FK_customer_3` FOREIGN KEY (`group_id`) REFERENCES `groups` (`group_id`) ON DELETE CASCADE,
CONSTRAINT `FK_customer_4` FOREIGN KEY (`type_id`) REFERENCES `types` (`type_id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;


I wrote a migration file with the following:



Schema::create('customers', function (Blueprint $table) {
$table->increments('id');
$table->string('name',50);
$table->string('address',100)->nullable();
$table->string('email',50)->nullable();
$table->integer('type_id')->unsigned()->index();
$table->integer('district_id')->unsigned()->index();
$table->integer('city_id')->unsigned()->index();
$table->integer('business_id')->unsigned()->index();
$table->integer('group_id')->unsigned()->index();
$table->timestamps();

$table->foreign(['district_id','city_id'])->references(['district_id','city_id'])->on('cities')->onDelete('cascade');
$table->foreign('business_id')->references('business_id')->on('businesses')->onDelete('cascade');
$table->foreign('type_id')->references('type_id')->on('types')->onDelete('cascade');
$table->foreign('group_id')->references('group_id')->on('groups')->onDelete('cascade');
});


But when I run the migration it gives me the following error.



SQLSTATE[HY000]: General error: 1005 Can't create table `wastewater`.`#sql-5a8_18a` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `customers` add constraint `customers_district_id_city_id_foreign` foreign key (`district_id`, `city_id`) references `cities` (`district_id`, `city_id`) on delete cascade)`


How can I this?










share|improve this question





























    0















    I want to create a table with multiple foreign keys. Here is the sql:



    CREATE TABLE `customers` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `name` varchar(50) DEFAULT NULL,
    `address` varchar(100) DEFAULT NULL,
    `email` varchar(50) DEFAULT NULL,
    `type_id` tinyint(3) unsigned DEFAULT NULL,
    `district_id` tinyint(3) unsigned DEFAULT NULL,
    `city_id` tinyint(3) unsigned DEFAULT NULL,
    `business_id` tinyint(3) unsigned DEFAULT NULL,
    `group_id` tinyint(3) unsigned DEFAULT NULL,
    PRIMARY KEY (`id`),
    KEY `FK_customer_1` (`district_id`,`city_id`),
    KEY `FK_customer_2` (`business_id`),
    KEY `FK_customer_3` (`group_id`),
    KEY `FK_customer_4` (`type_id`),
    CONSTRAINT `FK_customer_1` FOREIGN KEY (`district_id`, `city_id`)
    REFERENCES `cities` (`district_id`, `city_id`) ON DELETE CASCADE,
    CONSTRAINT `FK_customer_2` FOREIGN KEY (`business_id`) REFERENCES `businesses` (`business_id`) ON DELETE CASCADE,
    CONSTRAINT `FK_customer_3` FOREIGN KEY (`group_id`) REFERENCES `groups` (`group_id`) ON DELETE CASCADE,
    CONSTRAINT `FK_customer_4` FOREIGN KEY (`type_id`) REFERENCES `types` (`type_id`) ON DELETE CASCADE
    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;


    I wrote a migration file with the following:



    Schema::create('customers', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name',50);
    $table->string('address',100)->nullable();
    $table->string('email',50)->nullable();
    $table->integer('type_id')->unsigned()->index();
    $table->integer('district_id')->unsigned()->index();
    $table->integer('city_id')->unsigned()->index();
    $table->integer('business_id')->unsigned()->index();
    $table->integer('group_id')->unsigned()->index();
    $table->timestamps();

    $table->foreign(['district_id','city_id'])->references(['district_id','city_id'])->on('cities')->onDelete('cascade');
    $table->foreign('business_id')->references('business_id')->on('businesses')->onDelete('cascade');
    $table->foreign('type_id')->references('type_id')->on('types')->onDelete('cascade');
    $table->foreign('group_id')->references('group_id')->on('groups')->onDelete('cascade');
    });


    But when I run the migration it gives me the following error.



    SQLSTATE[HY000]: General error: 1005 Can't create table `wastewater`.`#sql-5a8_18a` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `customers` add constraint `customers_district_id_city_id_foreign` foreign key (`district_id`, `city_id`) references `cities` (`district_id`, `city_id`) on delete cascade)`


    How can I this?










    share|improve this question



























      0












      0








      0








      I want to create a table with multiple foreign keys. Here is the sql:



      CREATE TABLE `customers` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `name` varchar(50) DEFAULT NULL,
      `address` varchar(100) DEFAULT NULL,
      `email` varchar(50) DEFAULT NULL,
      `type_id` tinyint(3) unsigned DEFAULT NULL,
      `district_id` tinyint(3) unsigned DEFAULT NULL,
      `city_id` tinyint(3) unsigned DEFAULT NULL,
      `business_id` tinyint(3) unsigned DEFAULT NULL,
      `group_id` tinyint(3) unsigned DEFAULT NULL,
      PRIMARY KEY (`id`),
      KEY `FK_customer_1` (`district_id`,`city_id`),
      KEY `FK_customer_2` (`business_id`),
      KEY `FK_customer_3` (`group_id`),
      KEY `FK_customer_4` (`type_id`),
      CONSTRAINT `FK_customer_1` FOREIGN KEY (`district_id`, `city_id`)
      REFERENCES `cities` (`district_id`, `city_id`) ON DELETE CASCADE,
      CONSTRAINT `FK_customer_2` FOREIGN KEY (`business_id`) REFERENCES `businesses` (`business_id`) ON DELETE CASCADE,
      CONSTRAINT `FK_customer_3` FOREIGN KEY (`group_id`) REFERENCES `groups` (`group_id`) ON DELETE CASCADE,
      CONSTRAINT `FK_customer_4` FOREIGN KEY (`type_id`) REFERENCES `types` (`type_id`) ON DELETE CASCADE
      ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;


      I wrote a migration file with the following:



      Schema::create('customers', function (Blueprint $table) {
      $table->increments('id');
      $table->string('name',50);
      $table->string('address',100)->nullable();
      $table->string('email',50)->nullable();
      $table->integer('type_id')->unsigned()->index();
      $table->integer('district_id')->unsigned()->index();
      $table->integer('city_id')->unsigned()->index();
      $table->integer('business_id')->unsigned()->index();
      $table->integer('group_id')->unsigned()->index();
      $table->timestamps();

      $table->foreign(['district_id','city_id'])->references(['district_id','city_id'])->on('cities')->onDelete('cascade');
      $table->foreign('business_id')->references('business_id')->on('businesses')->onDelete('cascade');
      $table->foreign('type_id')->references('type_id')->on('types')->onDelete('cascade');
      $table->foreign('group_id')->references('group_id')->on('groups')->onDelete('cascade');
      });


      But when I run the migration it gives me the following error.



      SQLSTATE[HY000]: General error: 1005 Can't create table `wastewater`.`#sql-5a8_18a` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `customers` add constraint `customers_district_id_city_id_foreign` foreign key (`district_id`, `city_id`) references `cities` (`district_id`, `city_id`) on delete cascade)`


      How can I this?










      share|improve this question
















      I want to create a table with multiple foreign keys. Here is the sql:



      CREATE TABLE `customers` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `name` varchar(50) DEFAULT NULL,
      `address` varchar(100) DEFAULT NULL,
      `email` varchar(50) DEFAULT NULL,
      `type_id` tinyint(3) unsigned DEFAULT NULL,
      `district_id` tinyint(3) unsigned DEFAULT NULL,
      `city_id` tinyint(3) unsigned DEFAULT NULL,
      `business_id` tinyint(3) unsigned DEFAULT NULL,
      `group_id` tinyint(3) unsigned DEFAULT NULL,
      PRIMARY KEY (`id`),
      KEY `FK_customer_1` (`district_id`,`city_id`),
      KEY `FK_customer_2` (`business_id`),
      KEY `FK_customer_3` (`group_id`),
      KEY `FK_customer_4` (`type_id`),
      CONSTRAINT `FK_customer_1` FOREIGN KEY (`district_id`, `city_id`)
      REFERENCES `cities` (`district_id`, `city_id`) ON DELETE CASCADE,
      CONSTRAINT `FK_customer_2` FOREIGN KEY (`business_id`) REFERENCES `businesses` (`business_id`) ON DELETE CASCADE,
      CONSTRAINT `FK_customer_3` FOREIGN KEY (`group_id`) REFERENCES `groups` (`group_id`) ON DELETE CASCADE,
      CONSTRAINT `FK_customer_4` FOREIGN KEY (`type_id`) REFERENCES `types` (`type_id`) ON DELETE CASCADE
      ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;


      I wrote a migration file with the following:



      Schema::create('customers', function (Blueprint $table) {
      $table->increments('id');
      $table->string('name',50);
      $table->string('address',100)->nullable();
      $table->string('email',50)->nullable();
      $table->integer('type_id')->unsigned()->index();
      $table->integer('district_id')->unsigned()->index();
      $table->integer('city_id')->unsigned()->index();
      $table->integer('business_id')->unsigned()->index();
      $table->integer('group_id')->unsigned()->index();
      $table->timestamps();

      $table->foreign(['district_id','city_id'])->references(['district_id','city_id'])->on('cities')->onDelete('cascade');
      $table->foreign('business_id')->references('business_id')->on('businesses')->onDelete('cascade');
      $table->foreign('type_id')->references('type_id')->on('types')->onDelete('cascade');
      $table->foreign('group_id')->references('group_id')->on('groups')->onDelete('cascade');
      });


      But when I run the migration it gives me the following error.



      SQLSTATE[HY000]: General error: 1005 Can't create table `wastewater`.`#sql-5a8_18a` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `customers` add constraint `customers_district_id_city_id_foreign` foreign key (`district_id`, `city_id`) references `cities` (`district_id`, `city_id`) on delete cascade)`


      How can I this?







      laravel-5






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 7:59









      Julian Stark

      1,3011527




      1,3011527










      asked Nov 23 '18 at 2:47









      AbaijAbaij

      3272722




      3272722
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Can you please Try this way, Just removed array and define with comma-separated only.



          Schema::create('customers', function (Blueprint $table) {
          $table->increments('id');
          $table->string('name',50);
          $table->string('address',100)->nullable();
          $table->string('email',50)->nullable();
          $table->integer('type_id')->unsigned()->index();
          $table->integer('district_id')->unsigned()->index();
          $table->integer('city_id')->unsigned()->index();
          $table->integer('business_id')->unsigned()->index();
          $table->integer('group_id')->unsigned()->index();
          $table->timestamps();

          $table->foreign('district_id','city_id')->references('district_id','city_id')->on('cities','cities')->onDelete('cascade','cascade');
          $table->foreign('business_id')->references('business_id')->on('businesses')->onDelete('cascade');
          $table->foreign('type_id')->references('type_id')->on('types')->onDelete('cascade');
          $table->foreign('group_id')->references('group_id')->on('groups')->onDelete('cascade');
          });





          share|improve this answer


























          • no, I think that's not the case. The second argument will create index name, not a key.

            – Abaij
            Nov 23 '18 at 9:36



















          0














          Try the following way, it will work.



          Schema::create('customers', function (Blueprint $table) {
          $table->increments('id');

          $table->integer('type_id', false, true);
          $table->foreign('type_id')->references('type_id')->on('types')
          ->onDelete('cascade');

          $table->integer('district_id', false, true);
          $table->foreign('district_id')
          ->references('district_id')->on('cities')
          ->onDelete('cascade');

          $table->integer('city_id', false, true);
          $table->foreign('city_id')
          ->references('city_id')->on('cities')
          ->onDelete('cascade');

          $table->integer('business_id', false, true);
          $table->foreign('business_id')->references('business_id')
          ->on('businesses')->onDelete('cascade');

          $table->integer('group_id', false, true);
          $table->foreign('group_id')->references('group_id')->on('groups')
          ->onDelete('cascade');
          $table->string('name',50);
          $table->string('address',100)->nullable();
          $table->string('email',50)->nullable();
          $table->timestamps();
          });





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440088%2fhow-to-create-laravel-migration-for-tables-with-multiple-foreign-keys%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Can you please Try this way, Just removed array and define with comma-separated only.



            Schema::create('customers', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name',50);
            $table->string('address',100)->nullable();
            $table->string('email',50)->nullable();
            $table->integer('type_id')->unsigned()->index();
            $table->integer('district_id')->unsigned()->index();
            $table->integer('city_id')->unsigned()->index();
            $table->integer('business_id')->unsigned()->index();
            $table->integer('group_id')->unsigned()->index();
            $table->timestamps();

            $table->foreign('district_id','city_id')->references('district_id','city_id')->on('cities','cities')->onDelete('cascade','cascade');
            $table->foreign('business_id')->references('business_id')->on('businesses')->onDelete('cascade');
            $table->foreign('type_id')->references('type_id')->on('types')->onDelete('cascade');
            $table->foreign('group_id')->references('group_id')->on('groups')->onDelete('cascade');
            });





            share|improve this answer


























            • no, I think that's not the case. The second argument will create index name, not a key.

              – Abaij
              Nov 23 '18 at 9:36
















            0














            Can you please Try this way, Just removed array and define with comma-separated only.



            Schema::create('customers', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name',50);
            $table->string('address',100)->nullable();
            $table->string('email',50)->nullable();
            $table->integer('type_id')->unsigned()->index();
            $table->integer('district_id')->unsigned()->index();
            $table->integer('city_id')->unsigned()->index();
            $table->integer('business_id')->unsigned()->index();
            $table->integer('group_id')->unsigned()->index();
            $table->timestamps();

            $table->foreign('district_id','city_id')->references('district_id','city_id')->on('cities','cities')->onDelete('cascade','cascade');
            $table->foreign('business_id')->references('business_id')->on('businesses')->onDelete('cascade');
            $table->foreign('type_id')->references('type_id')->on('types')->onDelete('cascade');
            $table->foreign('group_id')->references('group_id')->on('groups')->onDelete('cascade');
            });





            share|improve this answer


























            • no, I think that's not the case. The second argument will create index name, not a key.

              – Abaij
              Nov 23 '18 at 9:36














            0












            0








            0







            Can you please Try this way, Just removed array and define with comma-separated only.



            Schema::create('customers', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name',50);
            $table->string('address',100)->nullable();
            $table->string('email',50)->nullable();
            $table->integer('type_id')->unsigned()->index();
            $table->integer('district_id')->unsigned()->index();
            $table->integer('city_id')->unsigned()->index();
            $table->integer('business_id')->unsigned()->index();
            $table->integer('group_id')->unsigned()->index();
            $table->timestamps();

            $table->foreign('district_id','city_id')->references('district_id','city_id')->on('cities','cities')->onDelete('cascade','cascade');
            $table->foreign('business_id')->references('business_id')->on('businesses')->onDelete('cascade');
            $table->foreign('type_id')->references('type_id')->on('types')->onDelete('cascade');
            $table->foreign('group_id')->references('group_id')->on('groups')->onDelete('cascade');
            });





            share|improve this answer















            Can you please Try this way, Just removed array and define with comma-separated only.



            Schema::create('customers', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name',50);
            $table->string('address',100)->nullable();
            $table->string('email',50)->nullable();
            $table->integer('type_id')->unsigned()->index();
            $table->integer('district_id')->unsigned()->index();
            $table->integer('city_id')->unsigned()->index();
            $table->integer('business_id')->unsigned()->index();
            $table->integer('group_id')->unsigned()->index();
            $table->timestamps();

            $table->foreign('district_id','city_id')->references('district_id','city_id')->on('cities','cities')->onDelete('cascade','cascade');
            $table->foreign('business_id')->references('business_id')->on('businesses')->onDelete('cascade');
            $table->foreign('type_id')->references('type_id')->on('types')->onDelete('cascade');
            $table->foreign('group_id')->references('group_id')->on('groups')->onDelete('cascade');
            });






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 23 '18 at 6:39









            Julian Stark

            1,3011527




            1,3011527










            answered Nov 23 '18 at 6:29









            Mayank MajithyaMayank Majithya

            1,064515




            1,064515













            • no, I think that's not the case. The second argument will create index name, not a key.

              – Abaij
              Nov 23 '18 at 9:36



















            • no, I think that's not the case. The second argument will create index name, not a key.

              – Abaij
              Nov 23 '18 at 9:36

















            no, I think that's not the case. The second argument will create index name, not a key.

            – Abaij
            Nov 23 '18 at 9:36





            no, I think that's not the case. The second argument will create index name, not a key.

            – Abaij
            Nov 23 '18 at 9:36













            0














            Try the following way, it will work.



            Schema::create('customers', function (Blueprint $table) {
            $table->increments('id');

            $table->integer('type_id', false, true);
            $table->foreign('type_id')->references('type_id')->on('types')
            ->onDelete('cascade');

            $table->integer('district_id', false, true);
            $table->foreign('district_id')
            ->references('district_id')->on('cities')
            ->onDelete('cascade');

            $table->integer('city_id', false, true);
            $table->foreign('city_id')
            ->references('city_id')->on('cities')
            ->onDelete('cascade');

            $table->integer('business_id', false, true);
            $table->foreign('business_id')->references('business_id')
            ->on('businesses')->onDelete('cascade');

            $table->integer('group_id', false, true);
            $table->foreign('group_id')->references('group_id')->on('groups')
            ->onDelete('cascade');
            $table->string('name',50);
            $table->string('address',100)->nullable();
            $table->string('email',50)->nullable();
            $table->timestamps();
            });





            share|improve this answer




























              0














              Try the following way, it will work.



              Schema::create('customers', function (Blueprint $table) {
              $table->increments('id');

              $table->integer('type_id', false, true);
              $table->foreign('type_id')->references('type_id')->on('types')
              ->onDelete('cascade');

              $table->integer('district_id', false, true);
              $table->foreign('district_id')
              ->references('district_id')->on('cities')
              ->onDelete('cascade');

              $table->integer('city_id', false, true);
              $table->foreign('city_id')
              ->references('city_id')->on('cities')
              ->onDelete('cascade');

              $table->integer('business_id', false, true);
              $table->foreign('business_id')->references('business_id')
              ->on('businesses')->onDelete('cascade');

              $table->integer('group_id', false, true);
              $table->foreign('group_id')->references('group_id')->on('groups')
              ->onDelete('cascade');
              $table->string('name',50);
              $table->string('address',100)->nullable();
              $table->string('email',50)->nullable();
              $table->timestamps();
              });





              share|improve this answer


























                0












                0








                0







                Try the following way, it will work.



                Schema::create('customers', function (Blueprint $table) {
                $table->increments('id');

                $table->integer('type_id', false, true);
                $table->foreign('type_id')->references('type_id')->on('types')
                ->onDelete('cascade');

                $table->integer('district_id', false, true);
                $table->foreign('district_id')
                ->references('district_id')->on('cities')
                ->onDelete('cascade');

                $table->integer('city_id', false, true);
                $table->foreign('city_id')
                ->references('city_id')->on('cities')
                ->onDelete('cascade');

                $table->integer('business_id', false, true);
                $table->foreign('business_id')->references('business_id')
                ->on('businesses')->onDelete('cascade');

                $table->integer('group_id', false, true);
                $table->foreign('group_id')->references('group_id')->on('groups')
                ->onDelete('cascade');
                $table->string('name',50);
                $table->string('address',100)->nullable();
                $table->string('email',50)->nullable();
                $table->timestamps();
                });





                share|improve this answer













                Try the following way, it will work.



                Schema::create('customers', function (Blueprint $table) {
                $table->increments('id');

                $table->integer('type_id', false, true);
                $table->foreign('type_id')->references('type_id')->on('types')
                ->onDelete('cascade');

                $table->integer('district_id', false, true);
                $table->foreign('district_id')
                ->references('district_id')->on('cities')
                ->onDelete('cascade');

                $table->integer('city_id', false, true);
                $table->foreign('city_id')
                ->references('city_id')->on('cities')
                ->onDelete('cascade');

                $table->integer('business_id', false, true);
                $table->foreign('business_id')->references('business_id')
                ->on('businesses')->onDelete('cascade');

                $table->integer('group_id', false, true);
                $table->foreign('group_id')->references('group_id')->on('groups')
                ->onDelete('cascade');
                $table->string('name',50);
                $table->string('address',100)->nullable();
                $table->string('email',50)->nullable();
                $table->timestamps();
                });






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 '18 at 9:19









                engrhussainahmadengrhussainahmad

                1409




                1409






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440088%2fhow-to-create-laravel-migration-for-tables-with-multiple-foreign-keys%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                    Alcedinidae

                    Origin of the phrase “under your belt”?