SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails Laravel
<p>I have two tables, one for users and one for the new items. I have reference for the id in the users table in the items table. </p>

<pre><code> public function up()
    {
        Schema::create('items', function (Blueprint $table) {
            $table-&gt;increments('id');
            $table-&gt;integer('user_id')-&gt;unsigned();
            $table-&gt;string('item_title');
            $table-&gt;timestamps();
        });

        Schema::table('items', function($table) {
             $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users');
        });
</code></pre>

<p>This is my controller for adding new item</p>

<pre><code>public function storeItem(Request $request){
        $user = Auth::user();

        $item = new Item([
            'user_id' =&gt; $user-&gt;id,
            'item_title' =&gt; $request-&gt;input('title'),
        ]);

        $item-&gt;save();    
    }
</code></pre>

<p>But when I submit the form I have this error <code>SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (</code>database<code>.</code>items<code>, CONSTRAINT</code>items_user_id_foreign<code>FOREIGN KEY (</code>user_id<code>) REFERENCES</code>users<code>(</code>id<code>))</code> </p>

<p>Any ideas?</p>