SQLSTATE[42S02]: Base table or view not found: 1146 Table 'forge.decisions' doesn't exist

Published 6 months ago by aajiboo

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'forge.decisions' doesn't exist (SQL: select count(*) as aggregate from decisions where done = 0)

In Connection.php line 319:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'forge.decisions' doesn't exist

Script php artisan optimize handling the post-install-cmd event returned with error code 1

Best Answer (As Selected By aajiboo)
tykus
// RegisterController.php
protected function validator(array $data)
{
    return Validator::make($data, [
        'username' =>'required|unique:users,
        'name' => 'required|max:255',
        'email' => 'required|email|max:255|unique:users',
        'password' => 'required|min:6|confirmed',
    ]);
}


protected function create(array $data)
{
    return User::create([
        'username' => $data['name'],
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
    ]);
}

Of course, you need to send a username to the controller, so add a field to the registration form:

// register.blade.php
<div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}">
    <label for="username" class="col-md-4 control-label">username</label>

    <div class="col-md-6">
        <input id="username" type="text" class="form-control" name="username" value="{{ old('username') }}" required autofocus>

        @if ($errors->has('username'))
            <span class="help-block">
                <strong>{{ $errors->first('username') }}</strong>
            </span>
        @endif
    </div>
</div>  

tykus
tykus
6 months ago (623,140 XP)

Your problem is this line in the AppServiceProvider:

$badge = Decision::where('done',false)->count();

Comment it out until you run your migrations.

aajiboo

how i correct it?

tykus
tykus
6 months ago (623,140 XP)

Comment it out until you run your migrations.

-- Me - 2 minutes ago

aajiboo

didnt work!

tykus
tykus
6 months ago (623,140 XP)

Same error? Or did the next line throw an undefined variable $badge error?

aajiboo

yes

tykus
tykus
6 months ago (623,140 XP)

Ok, in that case, let's try wrapping it:

public function boot()
{
    Schema::defaultStringLength(191);
    if (Schema::hasTable('decisions')) {
        $badge = Decision::where('done',false)->count();
        View::share('badge',$badge);
    }
}
aajiboo

In Facade.php line 221:

Call to undefined method Illuminate\Database\Schema\MySqlBuilder::has()

tykus
tykus
6 months ago (623,140 XP)

hasTable, not has - edited above

aajiboo

now i've got another exception in register : QueryException SQLSTATE[HY000]: General error: 1364 Field 'username' doesn't have a default value (SQL: insert into users (name, email, password, updated_at, created_at) values (bb, [email protected], $2y$10$CoPaTVY5XIDpwRsbXt2wcuipDOnecL0AKx66qwKs4d8gnlrsvFqYK, 2018-02-08 15:30:44, 2018-02-08 15:30:44))

tykus
tykus
6 months ago (623,140 XP)

Completely different issue.

Have you modified the users table migration to add a username column? Have you updated the form / controller to use this username field rather than (or in addition to) the default name?

aajiboo

yes

tykus
tykus
6 months ago (623,140 XP)

Can you share the relevant code? I ask because your RegisterController has this create method:

    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }

and your registration form has no reference to username either!

aajiboo
tykus
tykus
6 months ago (623,140 XP)

That's the code I was referring to above. There is nothing about a username property anywhere related to your registration functionality.

Please sign in or create an account to participate in this conversation.