title: Laravel Database Schema, Nullable Foreign
body: <p>I've these two database tables:</p>
  
  <ol>
  <li>User Tables</li>
  <li>Partner Tables</li>
  </ol>
  
  <p><strong>User Tables</strong> will handle this kind of informations</p>
  
  <pre><code>Schema::create('users', function (Blueprint $table) {
        $table-&gt;increments('id')-&gt;unique();
        $table-&gt;string('email')-&gt;unique();
        $table-&gt;string('username')-&gt;unique();
        $table-&gt;string('password', 60);
        $table-&gt;string('photo')-&gt;nullable();
        $table-&gt;integer('partner_id')-&gt;unsigned();
        $table-&gt;foreign('partner_id')-&gt;references('id')-&gt;on('partners');
        $table-&gt;rememberToken();
        $table-&gt;timestamps();
  });
  </code></pre>
  
  <p>While <strong>Partner Tables</strong> will contains all the user meta information such as first name and last name, etc.</p>
  
  <pre><code>Schema::create('partners', function (Blueprint $table) {
  
      /**
       * Identity Columns
       */
      $table-&gt;increments('id')-&gt;unique();
      $table-&gt;string('first_name');
      $table-&gt;string('middle_name')-&gt;nullable();
      $table-&gt;string('last_name')-&gt;nullable();
      $table-&gt;string('display_name')-&gt;nullable();
      $table-&gt;string('email')-&gt;unique()-&gt;nullable();
      $table-&gt;string('website')-&gt;nullable();
      $table-&gt;string('phone')-&gt;nullable();
      $table-&gt;string('mobile')-&gt;nullable();
      $table-&gt;string('fax')-&gt;nullable();
      $table-&gt;date('birthdate')-&gt;nullable();
      $table-&gt;longText('bio')-&gt;nullable();
      $table-&gt;string('lang')-&gt;nullable(); //Language
  
      /**
       * Address Columns
       */
      $table-&gt;text('street')-&gt;nullable();
      $table-&gt;text('street2')-&gt;nullable();
      $table-&gt;integer('country_id')-&gt;unsigned(); // foreign
      $table-&gt;foreign('country_id')-&gt;references('id')-&gt;on('countries');
      $table-&gt;integer('state_id')-&gt;unsigned();   // foreign
      $table-&gt;foreign('state_id')-&gt;references('id')-&gt;on('country_states');
      $table-&gt;string('city')-&gt;nullable();
      $table-&gt;string('district')-&gt;nullable();
      $table-&gt;string('area')-&gt;nullable();
      $table-&gt;string('zip')-&gt;nullable();
  });
  </code></pre>
  
  <p>When a user is register to the site I only want few fields which are, <code>username</code>, <code>email address</code>, <code>password</code>, <code>first name</code> and <code>last name</code>. These are only the required fields.</p>
  
  <p>So information in partner tables can be filled later after the user have finish registering to the site.</p>
  
  <p>But due to the structure of foreign key, I cannot proceed any further because of this error :</p>
  
  <pre><code>SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`mytable`.`tbl_partners`, CONSTRAINT `partners_country_id_foreign` FOREIGN KEY (`country_id`) REFERENCES `tbl_countries` (`id`)) (SQL: insert into `tbl_partners` (`first_name`, `last_name`, `display_name`, `email`, `updated_at`, `created_at`) values (Jack, Wilson, admin, admin@example.com, 2016-06-09 19:41:18, 2016-06-09 19:41:18))
  </code></pre>
  
  <p>I know this is cause by the countries table which is required by the partner table.<br>
  My question is : is there a work around so I can fill the country or any other non required data on partner table but keep the foreign table schema for countries, states, etc.</p>