我已经填写各个领域,但仍显示laravel为什么SQLSTATE [HY000]在用户表?

问题描述 投票:1回答:1

我已经在用户的桌上摆满每个必填字段,但仍然收到这个错误:

SQLSTATE[HY000]: General error: 1364 Field 'profession' doesn't have a default value (SQL: insert into `users` (`name`, `email`, `password`, `updated_at`, `created_at`) values (Tushar Saha, [email protected], $2y$10$LDoHlFMH6irkn4riSaAA6evH.BxBw77HBKtluIAAn/gE2R9OmXfKy, 2019-02-08 13:13:25, 2019-02-08 13:13:25))

参数:

"SQLSTATE[HY000]: General error: 1364 Field 'profession' doesn't have a default value (SQL: insert into `users` (`name`, `email`, `password`, `updated_at`, `created_at`) values (Tushar Saha, [email protected], $2y$10$LDoHlFMH6irkn4riSaAA6evH.BxBw77HBKtluIAAn/gE2R9OmXfKy, 2019-02-08 13:13:25, 2019-02-08 13:13:25))

我有双重检查的行业拼写

  1. 在迁移文件夹
  2. 在视图页面
  3. 在寄存器控制器

我还要检查在网络部分的贴值:

_token  
"D9UB2NCdncIsorcsqmJGiy2QJZq0D5YSirnbBz5W"
name    "Tushar Saha"

profession  "Student"

email   "[email protected]"

password    "111111"

password_confirmation   "111111"

RegisterController.php

protected function validator(array $data)
{
    return Validator::make($data, [
        'name' => ['required', 'string', 'max:255'],
        'profession' => ['required', 'string', 'max:255'],
        'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
        'password' => ['required', 'string', 'min:6', 'confirmed'],
    ]);
}

在迁移:

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('profession');
        $table->string('email')->unique();
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        $table->tinyInteger('role')->default('3');
        $table->rememberToken();
        $table->timestamps();
    });
}

鉴于

<div class="form-group row">
                            <label for="profession" class="col-md-4 col-form-label text-md-right">{{ __('Profession') }}</label>

                            <div class="col-md-6">

                                <select name="profession" class="form-control{{ $errors->has('profession') ? ' is-invalid' : '' }}" value="{{ old('profession') }}" required autofocus>
                                    <option value="">Select One</option>
                                    <option value="Student">Student</option>
                                    <option value="Employed">Employed</option>
                                    <option value="Business Man">Business Man</option>
                                </select>

                                @if ($errors->has('profession'))
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $errors->first('profession') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

我在想什么?

php laravel
1个回答
2
投票

我要去无路可退,并帮助你,你似乎不被响应的人:

之一:

“专业”是在你protected $fillable型号搜索User丢失,它应该是这样的:

class CmsUser extends Authenticatable
{

    protected $fillable = [
        'name', 'email', 'profession', 'password',

...
}

或者,你的控制器是不正确的,缺少像

$user->profession = $request('profession')

请提供更多资讯

© www.soinside.com 2019 - 2024. All rights reserved.