php - SQLSTATE [23000]:违反完整性约束:1048 列“tempat_lahir”不能为空
问题描述
我尝试从用户那里更新配置文件,所以首先我将为 tempat_lahir 进行插入
这是我的控制器
public function getUpdateProfile()
{
return view('update_profile');
}
public function postUpdateProfile(Request $request)
{
User::create([
'tempat_lahir' => $request->tempat_lahir,
]);
这是我的迁移
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->string('tempat_lahir');
});
}
这是我的 User.php
protected $fillable = [
'tempat_lahir'
];
这是我的 web.php
Route::get('/update_profile', 'AuthController@getUpdateProfile')->middleware('auth');
Route::get('/update_profile', 'AuthController@postUpdateProfile')->name('update_profile')->middleware('auth');
解决方案
你只需要编辑迁移文件
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->string('tempat_lahir')->nullable();
});
}
和新鲜的 laravel 迁移
或编辑tempat_lahir
数据库中的列以添加nullable
属性;
你也应该编辑RegisterController.php
给数据表格来填充tempat_lahir
列
推荐阅读
- testing - 如何重用 puppeteer 测试
- distributed-database - `ERROR 9001 (HY000): PD server timeoutstart timestamp may fall behind safepoint` 在 TiDB 中
- google-fabric - librashlitics 在构建中不存在
- sql - 当我尝试通过不存在的列名过滤 information_schema.columns.column_name 时,Postgres 引发错误
- dns - Mailgun 电子邮件被某些提供商拒绝
- javascript - 单击多个元素时jQuery更改图标
- reactjs - 我应该将默认反应属性设置为 null
- java - 当我通过 Jenkins 使用 Maven 构建 Spring Boot 应用程序并执行 JAR 文件时,找不到类定义?
- firebase - firebase 设置后台消息处理程序
- python - 将全角 Unicode 字符转换为 ASCII 字符