L
L
lil_koi2020-01-22 19:04:13
Laravel
lil_koi, 2020-01-22 19:04:13

Why is there an error when creating a post?

Illuminate\Database\QueryException
SQLSTATE[HY000]: General error: 1364 Field 'countrie' doesn't have a default value (SQL: insert into `post` (`category`, `name`, `description`, `updated_at`, `created_at`) values ​​(category, name, description, 2020-01-22 15:56:31, 2020-01-22 15:56:31))
Here comes such a terrible error. Most likely, I am sending some value to the database that it does not want to accept, but I don’t know which one it is swearing at.
What does my schema look like?

Schema::create('post', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string("name", 255);
            $table->text("description");
            $table->text("img")->nullable();
            $table->text("category");
            $table->text("countrie");
            $table->text("city_id");
            $table->text("address");
            $table->text("price");
            $table->timestamps();
        });

My Model
protected $table ='post';
    protected $fillable =[
        'name',
        'city_id',
        'address',
        'price',
        'category',
        'description'
    ];

And my controller for creating a post in the database (I don’t know why, let it be)
public function create(Request $request){
        $objPost = new Post();
        $objPost = $objPost::create([
            'category'=>'category',
            'name'=> 'name',
            'description'=>'description'
        ]);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
ChernovGV, 2020-01-22
@lil_koi

Swears that there is no default value for countrie. You need to:
- either fix the database, remove not null
- either fix the database, set default
- or pass countrie

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question