title: SQLSTATE[HY000]: General error: 1364 Field 'accepted' doesn't have a default value
body: <p>Hello I am attempting to create a friend system somewhat like the Facebook where you can add another user as a friend however, once I click the button add friend it gives me this error. Any help will be very much appreciated thank you.</p>
  
  <blockquote>
    <p>SQLSTATE[HY000]: General error: 1364 Field 'accepted' doesn't have a
    default value (SQL: insert into <code>friends</code> (<code>friend_id</code>, <code>user_id</code>)
    values (1, 3))</p>
  </blockquote>
  
  <p>User.php</p>
  
  <pre><code>&lt;?php
  
  namespace Kermode;
  
  use Illuminate\Foundation\Auth\User as Authenticatable;
  
  class User extends Authenticatable
  {
  
      /**
       * The attributes that are mass assignable.
       *
       * @var array
       */
      protected $fillable = [
          'first_name','last_name', 'email', 'password','gender',
  
      ];
  
  
      /**
       * The attributes that should be hidden for arrays.
       *
       * @var array
       */
      protected $hidden = [
          'password', 'remember_token',
      ];
  
      public function getName()
      {
        if ($this-&gt;first_name &amp;&amp; $this-&gt;last_name) {
          return "{$this-&gt;first_name} {$this-&gt;last_name}";
        }
        if ($this-&gt;first_name) {
          return $this-&gt;first_name;
        }
  
        return null;
        }
  
      public function getNameOrUsername()
        {
          return $this-&gt;getName() ?: $this-&gt;username;
        }
  
        public function getFirstNameOrUsername()
        {
          return $this-&gt;first_name ?: $this-&gt;username;
        }
  
        public function getAvatarUrl()
          {
            return "https://www.gravatar.com/avatar/{{ md5($this-&gt;email) }}
            ?d=mm&amp;s=40";
          }
        public function friendsOfMine()
        {
          return $this-&gt;belongsToMany('Kermode\User', 'friends', 'user_id',
          'friend_id');
        }
        public function friendOf()
        {
          return $this-&gt;belongsToMany('Kermode\User' , 'friends', 'friend_id'
          , 'user_id');
        }
        public function friends()
        {
          return $this-&gt;friendsOfMine()-&gt;wherePivot('accepted', true)-&gt;get()-&gt;
          merge($this-&gt;friendOf()-&gt;wherePivot('accepted', true)-&gt;get());
        }
        public function friendRequests()
        {
          return $this-&gt;friendsOfMine()-&gt;wherePivot('accepted', false)-&gt;get();
        }
        public function friendRequestsPending()
        {
          return $this-&gt;friendOf()-&gt;wherePivot('accepted', false)-&gt;get();
        }
        public function hasFriendRequestPending(User $user)
        {
          return (bool) $this-&gt;friendRequestsPending()-&gt;where('id', $user-&gt;id)-&gt;
          count();
        }
        public function hasFriendRequestRecieved(User $user)
        {
          return (bool) $this-&gt;friendRequests()-&gt;where('id', $user-&gt;id)-&gt;count();
        }
        public function addFriend(User $user)
        {
          $this-&gt;friendOf()-&gt;attach($user-&gt;id);
        }
        public function acceptFriendRequest(User $user)
        {
          $this-&gt;friendRequests()-&gt;where('id', $user-&gt;id)-&gt;first()-&gt;pivot-&gt;
          update([
            'accepted' =&gt; true,
          ]);
        }
        public function isFriendsWith(User $user)
        {
          return (bool) $this-&gt;friends()-&gt;where('id', $user-&gt;id)-&gt;count();
        }
  }
  </code></pre>
  
  <p>FriendController.php</p>
  
  <pre><code>&lt;?php
  
  namespace Kermode\Http\Controllers;
  
  use Auth;
  use Kermode\User;
  use Illuminate\Http\Request;
  
  class FriendController extends Controller
  {
    public function getIndex()
    {
      $friends = Auth::user()-&gt;friends();
      $requests = Auth::user()-&gt;friendRequests();
  
      return view('friends.index')
        -&gt;with('friends', $friends)
        -&gt;with('requests', $requests);
    }
  
    public function getAdd($first_name)
    {
      $user = User::where('first_name', $first_name)-&gt;first();
  
      if (!$user) {
        return redirect()
          -&gt;route('home')
          -&gt;with('info', 'That user could not be found');
      }
  
      if (Auth::user()-&gt;hasFriendRequestPending($user) || $user-&gt;
          hasFriendRequestPending(Auth::user())) {
            return redirect()
              -&gt;route('profile.index', ['first_name' =&gt; $user-&gt;first_name])
              -&gt;with('info', 'Friend request already pending.');
  
      }
  
      if (Auth::user()-&gt;isFriendsWith($user)) {
          return redirect()
          -&gt;route('profile.index', ['first_name' =&gt; $user-&gt;firstname])
          -&gt;with('info', 'You are already friends');
  
      }
  
      Auth::user()-&gt;addFriend($user);
  
      return redirect()
        -&gt;route('profile.index', ['first_name' =&gt; $first_name])
        -&gt;with('info', 'Friend request sent.');
  
    }
  }
  </code></pre>
  
  <p>profile.index.blade.php</p>
  
  <pre><code>@extends('layouts.app')
  
  @section('content')
    &lt;div class="row"&gt;
      &lt;div class="col-leg-6"&gt;
        &lt;h3&gt;Your friends&lt;/h3&gt;
          @if (!$friends-&gt;count())
              &lt;p&gt;You have no friends&lt;/p&gt;
          @else
              @foreach ($friends as $user)
                @include('user/partials/userblock')
              @endforeach
          @endif
      &lt;/div&gt;
      &lt;div class="col-lg-6"&gt;
        &lt;h4&gt;Friend Request&lt;/h4&gt;
  
        @if (!$requests-&gt;count())
        &lt;p&gt;You have no friend requests.&lt;/p&gt;
        @else
          @foreach ($requests as $user)
            @include('user.partials.userblock')
          @endforeach
        @endif
      &lt;/div&gt;
    &lt;/div&gt;
  @endsection
  </code></pre>
  
  <p>friendstable</p>
  
  <pre><code>&lt;?php
  
  use Illuminate\Support\Facades\Schema;
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class CreateFriendsTable extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('friends', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;integer('user_id');
              $table-&gt;integer('friend_id');
              $table-&gt;boolean('accepted');
              $table-&gt;timestamps();
          });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::dropIfExists('friends');
      }
  }
  </code></pre>