[英]SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value laravel 5.5
[英]SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value in laravel
我正在使用 mysql v5.7 和 laravel v5.8。 我使用 auth 注册了 function ,当我尝试注册时显示错误。
SQLSTATE [HY000]:一般错误:1364 字段“名称”没有默认值(SQL:插入users
( email
, password
, updated_at
, created_at
)值(***@gmail.com,2yd4GvC,$2yd4Gv 05-25 19:53:37, 2020-05-25 19:53:37))
它在 localhost 中工作正常,但在将其添加到 ec2 服务器后显示此错误。
我更改了 config/database.php
像这样
'严格' => 假,
然后我可以注册,但名称列中没有值。
并且可以放置除名称列之外的其他列。
我不知道为什么它可以在本地服务器上运行,但在实时服务器中显示错误。
这是我的代码。
用户.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();
});
}
有谁能够帮我?
这个查询:
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)
不插入name
字段。 当该字段不能为 NULL MySQL 时会报错。
您在本地主机上没有收到此错误的原因可能是 MySQL 配置不那么严格。
设置'strict' => false,
将删除错误,但您的查询仍然不会插入name
字段值。
所以真正的解决方案是将你的数据库配置设置为严格(因为这样你会更快地注意到错误)。 然后更改您的查询,使其插入name
值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.