一般错误:1364字段'位置'没有默认值

时间:2017-06-02 02:24:43

标签: php mysql laravel sentinel

我使用laravel和sentinel创建一个登录系统 我添加了一个名为' location'在像这样的用户表中

Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('email');
    $table->string('password');
    $table->text('permissions')->nullable();
    $table->timestamp('last_login')->nullable();
    $table->string('first_name')->nullable();
    $table->string('last_name')->nullable();
    $table->string('location');   //this is my field
    $table->timestamps();
    $table->engine = 'InnoDB';
    $table->unique('email');
});

之后我运行代码进行迁移:刷新并将新字段添加到$ fillable list中,就像那样

protected $fillable = [
    'email',
    'password',
    'last_name',
    'first_name',
    'permissions',
    'location'
];

这也是我在控制器中的代码

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Sentinel;

class RegistrationController extends Controller
{
    public function register()
    {
        return view('authentication.register');
    }

    public function postRegister(Request $request)
    {
        $user = Sentinel::registerAndActivate($request->all());
        dd($user);
    }
}

当我插入新用户的数据时出现此错误

QueryException in Connection.php line 770: SQLSTATE[HY000]: General error: 1364 Field 'location' doesn't have a default value (SQL: insert into用户(电子邮件,如first_name ,的last_name ,密码,的updated_at , created_at ) values (elmasry200400@gmail.com, ahmed, masry, $2y$10$jAIN6mEXvayLXmY8JmnUHOAu36l3owetg3TuOHnpUtjs1uR89dEYm, 2017-06-02 00:49:53, 2017-06-02 00:49:53))

我尝试通过将strict strict更改为false来解决此问题但是消息错误仍然有效并且插入的行没有位置字段值 我在可填充数组中看到了位置字段,但我没有在属性数组中看到它 任何人都可以帮助我吗?

这是我的表格

<form action="/register" method="POST">
  {{ csrf_field() }}

  <div class="form-group">
     <div class="input-group">
        <span class="input-group-addon"><i class="fa fa-envelope"></i></span>

        <input type="email" name="email" class="form-control" placeholder="example@example.com">
     </div>                           
  </div>


  <div class="form-group">
     <div class="input-group">
        <span class="input-group-addon"><i class="fa fa-user"></i></span>

        <input type="text" name="first_name" class="form-control" placeholder="First Name">
     </div>                           
  </div>


  <div class="form-group">
     <div class="input-group">
        <span class="input-group-addon"><i class="fa fa-user"></i></span>

        <input type="text" name="last_name" class="form-control" placeholder="Last Name">
     </div>                           
  </div>


  <div class="form-group">
     <div class="input-group">
        <span class="input-group-addon"><i class="fa fa-map-marker"></i></span>

        <input type="text" name="lacation" class="form-control" placeholder="Location">
     </div>                           
  </div>


  <div class="form-group">
     <div class="input-group">
        <span class="input-group-addon"><i class="fa fa-lock"></i></span>

        <input type="password" name="password" class="form-control" placeholder="Password">
     </div>                           
  </div>

  <div class="form-group">
     <div class="input-group">
        <span class="input-group-addon"><i class="fa fa-lock"></i></span>

        <input type="password" name="password_confirmation" class="form-control" placeholder="Password Confirmation">
     </div>                           
  </div>

   <div class="form-group">

        <input type="submit" value="Register" class="btn btn-success pull-right">

  </div>                      
</form>

1 个答案:

答案 0 :(得分:1)

在您的表单中,您有

<input type="text" name="lacation" class="form-control" placeholder="Location">

请注意name="lacation"

的拼写错误

应为name="location"

<input type="text" name="location" class="form-control" placeholder="Location">