sqlstate[42s22]: column not found: 1054 unknown column 'description' in 'field list'

Issue

<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

class ListingFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
              'title' => $this->faker->sentence(),
              'tags' => 'laravel, api, backend',
              'company' => $this->faker->company(),
              'email' => $this->faker->companyEmail(),
              'website' => $this->faker->url(),
              'location' => $this->faker->city(),
              'description' => $this->faker->paragraph(2)
        ];
    }
}

this is the error it brings:

sqlstate[42s22]: column not found: 1054 unknown column ‘description’ in ‘field list’ (sql: insert into listings (title, tags, company, location, email, website, description, updated_at, created_at) values

Solution

You are missing it from the migration, please add

 
$schema->string('description')->nullable()
 

inside your database migration file located in database/migrations/<date_and_table_name>.php and run php artisan migrate:refresh or equivalent database migration command again.

Answered By – Patrik Grinsvall

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published