title: QueryException in Laravel 5 when executing Model::create
body: <p>I a newbie to Laravel. In my project there is a Model called Student and a table in MySQL student.</p>
  
  <p>When I am trying to insert some values to the database using Student::create , it gives me the following errors.</p>
  
  <p>The database table exists and I retrieved some values from another table before.</p>
  
  <p>My Insert Code in the Controller:</p>
  
  <pre><code>Student::create([
      'name' =&gt; Input::get('student_name'),
      'email' =&gt; Input::get('student_email',
      'contact' =&gt; Input::get('student_tel'),
      'reg_id' =&gt; Input::get('registration_no'),
      'password' =&gt; Hash::make(Input::get('password'))
  ]);
  </code></pre>
  
  <p>My Model Class:</p>
  
  <pre><code>&lt;?php namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Student extends Model {
  
      protected $table = 'student';
      protected $fillable = ['name', 'email', 'contact', 'username', 'password'];    
  }
  </code></pre>
  
  <p><strong>Complete Error for QueryException</strong></p>
  
  <blockquote>
    <p>QueryException in Connection.php line 620: SQLSTATE[42S02]: Base table
     or view not found: 1146 Table 'msc_project.tablename' doesn't exist
     (SQL: select count(*) as aggregate from <code>tablename</code> where
     <code>registration_no</code> = asgfsag)</p>
  </blockquote>
  
  <pre><code>``**in Connection.php line 620
  at Connection-&gt;runQueryCallback('select count(*) as aggregate from `tablename` where `registration_no` = ?', array('ffhfdh'), object(Closure)) in Connection.php line 576
  at Connection-&gt;run('select count(*) as aggregate from `tablename` where `registration_no` = ?', array('ffhfdh'), object(Closure)) in Connection.php line 293
  at Connection-&gt;select('select count(*) as aggregate from `tablename` where `registration_no` = ?', array('ffhfdh'), true) in Builder.php line 1377
  at Builder-&gt;runSelect() in Builder.php line 1367
  at Builder-&gt;getFresh(array('*')) in Builder.php line 1354
  at Builder-&gt;get(array('*')) in Builder.php line 1636
  at Builder-&gt;aggregate('count', array('*')) in Builder.php line 1574
  at Builder-&gt;count() in DatabasePresenceVerifier.php line 57
  at DatabasePresenceVerifier-&gt;getCount('tablename', 'registration_no', 'ffhfdh', null, null, array()) in Validator.php line 1057
  at Validator-&gt;validateUnique('registration_no', 'ffhfdh', array('tablename'), object(Validator)) in Validator.php line 372
  at Validator-&gt;validate('registration_no', 'unique:tablename') in Validator.php line 325
  at Validator-&gt;passes() in Validator.php line 347
  at Validator-&gt;fails() in StudentController.php line 56
  at StudentController-&gt;doRegistration()
  at call_user_func_array(array(object(StudentController), 'doRegistration'), array()) in Controller.php line 246
  at Controller-&gt;callAction('doRegistration', array()) in ControllerDispatcher.php line 162
  at ControllerDispatcher-&gt;call(object(StudentController), object(Route), 'doRegistration') in ControllerDispatcher.php line 107
  at ControllerDispatcher-&gt;Illuminate\Routing\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
  at Pipeline-&gt;then(object(Closure)) in ControllerDispatcher.php line 108
  at ControllerDispatcher-&gt;callWithinStack(object(StudentController), object(Route), object(Request), 'doRegistration') in ControllerDispatcher.php line 67
  at ControllerDispatcher-&gt;dispatch(object(Route), object(Request), 'App\Http\Controllers\StudentController', 'doRegistration') in Route.php line 198
  at Route-&gt;runWithCustomDispatcher(object(Request)) in Route.php line 131
  at Route-&gt;run(object(Request)) in Router.php line 691
  at Router-&gt;Illuminate\Routing\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
  at Pipeline-&gt;then(object(Closure)) in Router.php line 693
  at Router-&gt;runRouteWithinStack(object(Route), object(Request)) in Router.php line 660
  at Router-&gt;dispatchToRoute(object(Request)) in Router.php line 618
  at Router-&gt;dispatch(object(Request)) in Kernel.php line 210
  at Kernel-&gt;Illuminate\Foundation\Http\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43
  at VerifyCsrfToken-&gt;handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17
  at VerifyCsrfToken-&gt;handle(object(Request), object(Closure)) in Pipeline.php line 125
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
  at ShareErrorsFromSession-&gt;handle(object(Request), object(Closure)) in Pipeline.php line 125
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
  at StartSession-&gt;handle(object(Request), object(Closure)) in Pipeline.php line 125
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
  at AddQueuedCookiesToResponse-&gt;handle(object(Request), object(Closure)) in Pipeline.php line 125
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
  at EncryptCookies-&gt;handle(object(Request), object(Closure)) in Pipeline.php line 125
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
  at CheckForMaintenanceMode-&gt;handle(object(Request), object(Closure)) in Pipeline.php line 125
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
  at Pipeline-&gt;then(object(Closure)) in Kernel.php line 111
  at Kernel-&gt;sendRequestThroughRouter(object(Request)) in Kernel.php line 84
  at Kernel-&gt;handle(object(Request)) in index.php line 53
  at require_once('/home/pranavaghanan/Documents/GitHub Projects/MScApp/public/index.php') in server.php line 21
  </code></pre>
  
  <p><strong>Complete Error List for PDOException</strong></p>
  
  <blockquote>
    <p>PDOException in Connection.php line 288: SQLSTATE[42S02]: Base table
    or view not found: 1146 Table 'msc_project.tablename' doesn't exist</p>
  </blockquote>
  
  <pre><code>in Connection.php line 288
  at PDO-&gt;prepare('select count(*) as aggregate from `tablename` where `registration_no` = ?') in Connection.php line 288
  at Connection-&gt;Illuminate\Database\{closure}(object(MySqlConnection), 'select count(*) as aggregate from `tablename` where `registration_no` = ?', array('ffhfdh')) in Connection.php line 612
  at Connection-&gt;runQueryCallback('select count(*) as aggregate from `tablename` where `registration_no` = ?', array('ffhfdh'), object(Closure)) in Connection.php line 576
  at Connection-&gt;run('select count(*) as aggregate from `tablename` where `registration_no` = ?', array('ffhfdh'), object(Closure)) in Connection.php line 293
  at Connection-&gt;select('select count(*) as aggregate from `tablename` where `registration_no` = ?', array('ffhfdh'), true) in Builder.php line 1377
  at Builder-&gt;runSelect() in Builder.php line 1367
  at Builder-&gt;getFresh(array('*')) in Builder.php line 1354
  at Builder-&gt;get(array('*')) in Builder.php line 1636
  at Builder-&gt;aggregate('count', array('*')) in Builder.php line 1574
  at Builder-&gt;count() in DatabasePresenceVerifier.php line 57
  at DatabasePresenceVerifier-&gt;getCount('tablename', 'registration_no', 'ffhfdh', null, null, array()) in Validator.php line 1057
  at Validator-&gt;validateUnique('registration_no', 'ffhfdh', array('tablename'), object(Validator)) in Validator.php line 372
  at Validator-&gt;validate('registration_no', 'unique:tablename') in Validator.php line 325
  at Validator-&gt;passes() in Validator.php line 347
  at Validator-&gt;fails() in StudentController.php line 56
  at StudentController-&gt;doRegistration()
  at call_user_func_array(array(object(StudentController), 'doRegistration'), array()) in Controller.php line 246
  at Controller-&gt;callAction('doRegistration', array()) in ControllerDispatcher.php line 162
  at ControllerDispatcher-&gt;call(object(StudentController), object(Route), 'doRegistration') in ControllerDispatcher.php line 107
  at ControllerDispatcher-&gt;Illuminate\Routing\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
  at Pipeline-&gt;then(object(Closure)) in ControllerDispatcher.php line 108
  at ControllerDispatcher-&gt;callWithinStack(object(StudentController), object(Route), object(Request), 'doRegistration') in ControllerDispatcher.php line 67
  at ControllerDispatcher-&gt;dispatch(object(Route), object(Request), 'App\Http\Controllers\StudentController', 'doRegistration') in Route.php line 198
  at Route-&gt;runWithCustomDispatcher(object(Request)) in Route.php line 131
  at Route-&gt;run(object(Request)) in Router.php line 691
  at Router-&gt;Illuminate\Routing\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
  at Pipeline-&gt;then(object(Closure)) in Router.php line 693
  at Router-&gt;runRouteWithinStack(object(Route), object(Request)) in Router.php line 660
  at Router-&gt;dispatchToRoute(object(Request)) in Router.php line 618
  at Router-&gt;dispatch(object(Request)) in Kernel.php line 210
  at Kernel-&gt;Illuminate\Foundation\Http\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43
  at VerifyCsrfToken-&gt;handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17
  at VerifyCsrfToken-&gt;handle(object(Request), object(Closure)) in Pipeline.php line 125
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
  at ShareErrorsFromSession-&gt;handle(object(Request), object(Closure)) in Pipeline.php line 125
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
  at StartSession-&gt;handle(object(Request), object(Closure)) in Pipeline.php line 125
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
  at AddQueuedCookiesToResponse-&gt;handle(object(Request), object(Closure)) in Pipeline.php line 125
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
  at EncryptCookies-&gt;handle(object(Request), object(Closure)) in Pipeline.php line 125
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
  at CheckForMaintenanceMode-&gt;handle(object(Request), object(Closure)) in Pipeline.php line 125
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
  at Pipeline-&gt;then(object(Closure)) in Kernel.php line 111
  at Kernel-&gt;sendRequestThroughRouter(object(Request)) in Kernel.php line 84
  at Kernel-&gt;handle(object(Request)) in index.php line 53
  at require_once('/home/pranavaghanan/Documents/GitHub Projects/MScApp/public/index.php') in server.php line 21
  </code></pre>
  
  <p><strong>UPDATE :</strong></p>
  
  <p>I just found out that when comment out the code which is for Validation, the data goes into the database. Any idea why this line is causing the error?</p>
  
  <pre><code>$validator = \Validator::make($postedData, $rules, $messages);
  if ($validator-&gt;fails()) { 
      return Redirect::to('registration')-&gt;withInput()-&gt;withErrors($validator); 
  }
  </code></pre>
  
  <p>If I don't use \Validator it doesn't accept the class either.</p>