General error: 1364 Field'열 이름'doesn't have a default value 오류 처리 방법

4710 단어 MySQLlaravel8migrate
오류 개요
store 방법으로 DB에 데이터를 삽입할 때
오류 "General error: 1364 Field"열 이름 "doesn"t have a default value..."
나타났어.
결론
migrate에서null열을 허용하지 않습니다.
대응
데이터를 삽입하기 전에
nullable () 를 기억하고 스크롤해서migrate를 다시 만듭니다.
단말기
$ php artisan migrate:status
$ php artisan migrate:rollback --step=1
디렉토리 파일
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddImgToDbnameTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('dbname', function (Blueprint $table) {
-            $table->string("file_name")->after('content');
+            $table->string("file_name")->after('content')-->nullable();

-            $table->string("file_path")->after('content');
+            $table->string("file_path")->after('content')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('dbname', function (Blueprint $table) {
            $table->dropColumn("file_name");
            $table->dropColumn("file_path");
        });
    }
}
단말기
$ php artisan migrate 

좋은 웹페이지 즐겨찾기