0

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

2
  • You don`t have admin column in you User table. Commented Dec 28, 2018 at 5:53
  • 2
    @Saji show ur User model in question Commented Dec 28, 2018 at 6:16

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Done. But then return another error "PHP Error: Call to undefined method stdClass::save() in Psy Shell code on line 1"
Try this $me = new App\User $me = App\User::find(1) $me->admin = 1 $me->save()
0

Please remove admin in $fillable and try again

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.