Reputation: 503
I'm using mysql v5.7 and laravel v5.8. I made register function using by auth and when I try to register it's showing an error.
SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value
(SQL: insert into users
(email
, password
, updated_at
, created_at
) values (***@gmail.com, $2yd4GvC, 2020-05-25 19:53:37, 2020-05-25 19:53:37))
it's working fine in localhost but showing this error after adding it to ec2 server.
I changed config/database.php
like this
'strict' => false,
then i can register, but there is no value in name columns.
and can put other columns except for name column.
I don't know why it's works on local server but showing error in live server.
This is my code.
User.php
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
create_users_table.php
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
Can anybody help me?
Upvotes: 1
Views: 769
Reputation: 364
This query:
INSERT INTO users (email, password, updated_at, created_at)
VALUES (***@gmail.com, $2yd4GvC, 2020-05-25 19:53:37, 2020-05-25 19:53:37)
does not insert the name
field. When this field cannot be NULL MySQL will give an error.
The reason why you don't get this error on your localhost is probably that the MySQL config is less strict.
Setting 'strict' => false,
will remove the error, but your query still doesn't insert the name
field values.
So the real solution is to keep your database config set to strict (because then you will notice errors much faster). And then change your query so it will insert the name
value.
Upvotes: 1