Skip to content
Advertisement

Laravel Database Schema, Nullable Foreign

I’ve these two database tables:

  1. User Tables
  2. Partner Tables

User Tables will handle this kind of informations

JavaScript

While Partner Tables will contains all the user meta information such as first name and last name, etc.

JavaScript

When a user is register to the site I only want few fields which are, username, email address, password, first name and last name. These are only the required fields.

So information in partner tables can be filled later after the user have finish registering to the site.

But due to the structure of foreign key, I cannot proceed any further because of this error :

JavaScript

I know this is cause by the countries table which is required by the partner table.
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.

Advertisement

Answer

Set the country_id and the state_id nullable, like so.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement