laravel 未找到列:1054“字段列表”中的未知列“remember_token”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42873614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Column not found: 1054 Unknown column 'remember_token' in 'field list'?
提问by None
Im trying to do Auth:logout();
, but im getting this error. Do i really need this column or i can avoid that?
我正在尝试这样做Auth:logout();
,但我收到此错误。我真的需要这个专栏还是我可以避免?
Route::get('/logout', 'MainController@logout');
public function logout(){
Auth::logout();
return response()->json([
'isLoggedIn' => false
]);
}
回答by Alexey Mezenin
Looks like you've deleted the remember_token
from the users
table. Laravel uses this field by default, so you can just add the field back to the table:
看起来你已经remember_token
从users
表中删除了。Laravel 默认使用这个字段,所以你可以将该字段添加回表中:
$table->rememberToken();
Of course you could override some of Laravel methods to disable this functionality, but I wouldn't recommend that.
当然,您可以覆盖一些 Laravel 方法来禁用此功能,但我不建议这样做。
回答by Treasure
Simply go to 'up' function in your create_user_table migration and add
只需转到 create_user_table 迁移中的“up”功能并添加
$table->rememberToken();
to the schema remember too reset migration and carry out a fresh db:seed
到架构记住太重置迁移并执行新的 db:seed
回答by a3rxander
You could avoid that by using this on your User Model.
您可以通过在您的用户模型上使用它来避免这种情况。
/**
* Overrides the method to ignore the remember token.
*/
public function setAttribute($key, $value)
{
$isRememberTokenAttribute = $key == $this->getRememberTokenName();
if (!$isRememberTokenAttribute)
{
parent::setAttribute($key, $value);
}
}