lundi 22 mars 2021

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'field list'

I'm using Laravel 5.1 framework here.

So I'm trying to create a basic task list, but I keep getting an error because of the unknown column. It said:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'field list' (SQL: insert into tasks (name, updated_at, created_at) values (Laba, 2021-03-22 16:42:10, 2021-03-22 16:42:10))

Route

Route::post('/task', function (Request $request) {
    $validator = Validator::make($request->all(), [
        'name' => 'required|max:255',
    ]);

    if ($validator->fails()) {
        return redirect('/')
            ->withInput()
            ->withErrors($validator);
    }

    $task = new Task;
    $task->name = $request->name;
    $task->save();

    return redirect('/');
});

Migration

class CreateTasksTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('tasks', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('tasks');
    }
}

Model

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Task extends Model
{
    use HasFactory;
}

I can't find what column 'name' is unknown. What I did wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire