SQLSTATE [HY000]:常规错误 - 创建一个帐户

时间:2018-02-11 17:09:10

标签: laravel

我正在使用laravel auth。在注册页面中,用户需要填写姓名,电子邮件和密码才能创建帐户。之后,用户可以编辑他的个人资料帐户并插入更多信息,如地址,城市,邮政编码等,但要创建帐户,只需要姓名,姓名,电子邮件和密码。

我使用laravel auth使用下面的代码构建上面的逻辑,但是在填写表单并单击“创建帐户”后我收到错误:

SQLSTATE [HY000]:常规错误:1364字段'facebook_id'没有默认值(SQL:插入usersnameemail,{{1} },passwordupdated_at)值(...)

您知道下面代码中的错误是什么吗?

路线:

created_at

用户表格迁移:

Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');

用户模型:

class CreateUsersTable extends Migration
{
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('facebook_id')->unique();
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->string('phone');
            $table->dateTime('dateRegister');
            $table->string('address');
            $table->string('zipCode');
            $table->string('city');
            $table->timestamps();
        });
    }
   }

RegisterController:

   class User extends Authenticatable
{
    use Notifiable;

    protected $fillable = [
        'name', 'email', 'password', 'facebook_id', ''
    ];

    protected $hidden = [
        'password',
    ];
   }

4 个答案:

答案 0 :(得分:2)

如果在注册过程中您通过了Facebook ID,请添加:

Format of the initialization string does not conform to specification starting at index 0

如果没有,请将此列设为可为空:

return User::create([
    'name' => $data['name'],
    'email' => $data['email'],
    'password' => bcrypt($data['password']),
    'facebook_id' => $data['facebook_id']
]);

答案 1 :(得分:1)

更改您的/testcode/file2 "-3.588920831680E-02","1.601887196302E-01","1.302309112549E+02" "3.739478886127E-01","1.782759875059E-01","6.490543365479E+01" "3.298096954823E-01","6.939357519150E-02","2.112392578125E+02" "-2.319437451661E-02","1.149862855673E-01","2.712340698242E+0 并允许migration为空,否则facebook_id时提供facebook_id

inserting

答案 2 :(得分:0)

您需要将字段传递给带有值的create()方法,或者在迁移中将其设为nullable

$table->string('facebook_id')->unique()->nullable();

答案 3 :(得分:0)

如果您未提供facebook_idcreate方法,请在迁移文件中将其设为可空

$table->string('facebook_id')->unique()->nullable();