'Error when adding a new field to the users table in Laravel 8
I get the following error when adding a new field to the users table.
Illuminate\Database\QueryExceptionSQLSTATE[HY000]: General error: 1364 Field 'phone' doesn't have a default value (SQL: insert into
users(name,password,updated_at,created_at) values (mohamed, [email protected], $2y$10$j746o3piJ0zpz0dwhieK8emio2g38l2rppbkrueJLACDOwVU2uzYC, 2022-02-02 05:50:26, 2022-02-02 05:50:26))
This is the field I want to add: enter image description here
This is my schedule in PHPMyAdmin: enter image description here
Table
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email');
$table->timestamp('email_verified_at');
$table->string('password');
$table->string('phone');
$table->rememberToken();
$table->timestamps();
});
}
Model
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
protected $fillable = [
'name',
'email',
'password',
'phone',
];
protected $hidden = [
'password',
'remember_token',
];
protected $casts = [
'email_verified_at' => 'datetime',
];
}
View
<div>
<x-label for="phone" :value="__('Phone')"/>
<x-input id="phone" class="block mt-1 w-full" type="number"
name="phone" :value="old('phone')" required autofocus/>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
