0

사용자의 새 등록 세부 정보를 추가하려고합니다. 사용자의 LASTNAME을 입력합니다. 하지만 내 데이터베이스에 삽입하는 데 문제가 있습니다. 이는 오는 오류가 최대Laravel 5.3 : 사용자 등록을위한 추가 사용자 정보를 추가 할 수 없습니다.

ERROR : 이것은 내 데이터베이스 마이그레이션 파일이

QueryException in Connection.php line 761: SQLSTATE[HY000]: General error: 1364 Field 'f_lastname' doesn't have a default value (SQL: insert into users (name , email , password , updated_at , created_at) values (chu, [email protected], 111, 2016-10-12 06:55:33, 2016-10-12 06:55:33))

입니다

public function up() 
{ 
    Schema::create('users', function (Blueprint $table) { 
     $table->increments('id'); 
     $table->string('name'); 
     $table->string('f_lastname'); 
     $table->string('email')->unique(); 
     $table->string('password'); 
     $table->rememberToken(); 
     $table->timestamps(); 
    }); 
} 

user.php $ 채울 수있는 코드

class User extends Authenticatable 
{ 
use Notifiable; 

/** 
* The attributes that are mass assignable. 
* 
* @var array 
*/ 
protected $fillable = [ 
    'name', 'f_lastname', 'email', 'password', 
]; 

/** 
* The attributes that should be hidden for arrays. 
* 
* @var array 
*/ 
protected $hidden = [ 
    'password', 'remember_token', 
]; 
} 

등록 정보 r.php 검증 섹션

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

/** 
* Create a new user instance after a valid registration. 
* 
* @param array $data 
* @return User 
*/ 
protected function create(array $data) 
{ 
    return User::create([ 
     'name' => $data['name'], 
     'f_lastname' => $data['f_lastname'], 
     'email' => $data['email'], 
     'password' => bcrypt($data['password']), 
    ]); 
} 

내가 본 튜토리얼의 대부분은 laravel 5.2이었다. 나는 laravel 5.3을 사용하면서 막 새로 왔습니다. 도움이되는 사람들을 감사하십시오!

+0

가능한 중복 : 1364 필드 'display \ _name'에는 기본값이 없습니다.] (http://stackoverflow.com/questions/18751291/mysql-error-1364-field-display-name-doesnt-have-default-value) –

답변

1

오류 자체는 설명입니다.

f_lastname은 null이 아니며 기본값이 할당되어 있지 않습니다. 그래서 귀하의 쿼리에서 당신은 어떤 가치와 그 열을 포함하거나 테이블 구조를 변경하고 그것에 어떤 기본값을 할당하거나 null 허용 열로 만들어야합니다.

예 :

ALTER TABLE `user` CHANGE `f_lastname` `f_lastname` TEXT NULL 

또는 빈 문자열로에게 기본 값을 제공 :

변경 열이 null을 허용하는 [MySQL의 오류의

ALTER TABLE `user` CHANGE `f_lastname` `f_lastname` TEXT NOT NULL DEFAULT '' 
+0

정말 고마워요! 문제 해결됨! –

+0

멋진데 :) –