0
votes

I tried to create admin user using php artisan tinker. When I try to save, it return an error. Please help me to fix the issue.

Here is the error

Illuminate/Database/QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'admin' in 'field list' (SQL: update users set updated_at = 2018-12-28 05:41:31, admin = 1 where id = 1)'

enter image description here

3
You don`t have admin column in you User table.Prashant Deshmukh.....
@Saji show ur User model in questionJignesh Joisar

3 Answers

1
votes

You have no column named 'admin' in 'users' table of your database. Add an 'admin' column. This should solve the error.

0
votes

Please remove admin in $fillable and try again

0
votes

You must create a migration containing the new columns you want to add to your DB schema.

Example: (this will add a TINYINT admin column with 0 as default value)

<?php

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

class AddsAdminColumnToUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->tinyInteger('admin')->default(0);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn('admin');
        });
    }
}

Read more about Laravel Migrations here.