在Laravel 5.1 DB中重命名列时的例外情况

时间:2015-11-17 21:29:50

标签: php mysql laravel exception pdo

我刚刚在Laravel进行了迁移。我注意到在users表中有几列:id,name,email等。我将名为“name”的列更改为“username”,并将其作为唯一列。现在,当我启动我的应用程序并尝试注册时,我得到2个exeptions:QueryExpetion和PDOExeption。我认为我应该在Builder.php中改变一些东西,那里没有这样的东西。这些是我得到的错误。我需要改变什么?!

QueryException in Connection.php line 651: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'where clause' (SQL: select count(*) as aggregate from `users` where `name` = kosach)

in Connection.php line 651
at Connection->runQueryCallback('select count(*) as aggregate from `users` where `name` = ?', array('kosach'), object(Closure)) in Connection.php line 611
at Connection->run('select count(*) as aggregate from `users` where `name` = ?', array('kosach'), object(Closure)) in Connection.php line 324
at Connection->select('select count(*) as aggregate from `users` where `name` = ?', array('kosach'), true) in Builder.php line 1406
at Builder->runSelect() in Builder.php line 1383
at Builder->get(array('*')) in Builder.php line 1718
at Builder->aggregate('count', array('*')) in Builder.php line 1638
at Builder->count() in DatabasePresenceVerifier.php line 57
at DatabasePresenceVerifier->getCount('users', 'name', 'kosach', null, null, array()) in Validator.php line 1070
at Validator->validateUnique('name', 'kosach', array('users'), object(Validator)) in Validator.php line 362
at Validator->validate('name', 'unique:users') in Validator.php line 314
at Validator->passes() in Validator.php line 335
at Validator->fails() in RegistersUsers.php line 32
at AuthController->postRegister(object(Request))
at call_user_func_array(array(object(AuthController), 'postRegister'), array(object(Request))) in Controller.php line 256
at Controller->callAction('postRegister', array(object(Request))) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(AuthController), object(Route), 'postRegister') in ControllerDispatcher.php line 112
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in RedirectIfAuthenticated.php line 45
at RedirectIfAuthenticated->handle(object(Request), object(Closure))
at call_user_func_array(array(object(RedirectIfAuthenticated), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(AuthController), object(Route), object(Request), 'postRegister') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\Auth\AuthController', 'postRegister') in Route.php line 203
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 704
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 706
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 671
at Router->dispatchToRoute(object(Request)) in Router.php line 631
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54
Connection.php第319行中的

1/2 PDOException:SQLSTATE [42S22]:找不到列:1054'where子句'中的未知列'name'

in Connection.php line 319
at PDO->prepare('select count(*) as aggregate from `users` where `name` = ?') in Connection.php line 319
at Connection->Illuminate\Database\{closure}(object(MySqlConnection), 'select count(*) as aggregate from `users` where `name` = ?', array('kosach')) in Connection.php line 644
at Connection->runQueryCallback('select count(*) as aggregate from `users` where `name` = ?', array('kosach'), object(Closure)) in Connection.php line 611
at Connection->run('select count(*) as aggregate from `users` where `name` = ?', array('kosach'), object(Closure)) in Connection.php line 324
at Connection->select('select count(*) as aggregate from `users` where `name` = ?', array('kosach'), true) in Builder.php line 1406
at Builder->runSelect() in Builder.php line 1383
at Builder->get(array('*')) in Builder.php line 1718
at Builder->aggregate('count', array('*')) in Builder.php line 1638
at Builder->count() in DatabasePresenceVerifier.php line 57
at DatabasePresenceVerifier->getCount('users', 'name', 'kosach', null, null, array()) in Validator.php line 1070
at Validator->validateUnique('name', 'kosach', array('users'), object(Validator)) in Validator.php line 362
at Validator->validate('name', 'unique:users') in Validator.php line 314
at Validator->passes() in Validator.php line 335
at Validator->fails() in RegistersUsers.php line 32
at AuthController->postRegister(object(Request))
at call_user_func_array(array(object(AuthController), 'postRegister'), array(object(Request))) in Controller.php line 256
at Controller->callAction('postRegister', array(object(Request))) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(AuthController), object(Route), 'postRegister') in ControllerDispatcher.php line 112
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in RedirectIfAuthenticated.php line 45
at RedirectIfAuthenticated->handle(object(Request), object(Closure))
at call_user_func_array(array(object(RedirectIfAuthenticated), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(AuthController), object(Route), object(Request), 'postRegister') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\Auth\AuthController', 'postRegister') in Route.php line 203
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 704
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 706
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 671
at Router->dispatchToRoute(object(Request)) in Router.php line 631
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54

2 个答案:

答案 0 :(得分:3)

默认AuthController使用namecreate方法中创建用户。

this line的密钥更改为username

答案 1 :(得分:1)

即使你已经更改了数据库中列的名称,它看起来像你代码中的某个地方仍然引用name