#when ever i run any command it says this error

55 messages · Page 1 of 1 (latest)

bold mason
#

PS C:\xampp\htdocs\Script> php artisan migrate

   Illuminate\Database\QueryException 

  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'shozystock.users' doesn't exist (Connection: mysql, SQL: select count(*) as aggregate from `users` where `status` = active)

  at vendor\laravel\framework\src\Illuminate\Database\Connection.php:829
    825▕                     $this->getName(), $query, $this->prepareBindings($bindings), $e
    826▕                 );
    827▕             }
    828▕
  ➜ 829▕             throw new QueryException(
    830▕                 $this->getName(), $query, $this->prepareBindings($bindings), $e
    831▕             );
    832▕         }
    833▕     }

  1   [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(App\Providers\ViewServiceProvider))

  2   vendor\laravel\framework\src\Illuminate\Database\Connection.php:423
      PDOException::("SQLSTATE[42S02]: Base table or view not found: 1146 Table 'shozystock.users' doesn't exist")

#

when ever i run any command like

php artisan serve
php artisan migrate
php artisan migrate refresh

#

it gives me the same error

digital trench
#

what happens if you run php artisan migrate:status? It says your users table doesn't exist, so maybe the migration that creates it was completed at some point and then the table was deleted later?

#

also, if you want to use refresh, I think the command is php artisan migrate:refresh

bold mason
bold mason
#

i just wanna know when exactly is the problem idk where is the problem to fix it

digital trench
#

migrate:status should still work I believe, weird. That basically list all your migrations so far. Is this a new project? It could be something wrong with the migrations themselves

#

if you want to redo your whole database, php artisan migrate:fresh should work

bold mason
#

same error

   
   Illuminate\Database\QueryException 
   
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'shozystock.users' doesn't exist (Connection: mysql, SQL: select count(*) as aggregate from `users` where `status` = active)
   
  at vendor\laravel\framework\src\Illuminate\Database\Connection.php:829
    825▕                     $this->getName(), $query, $this->prepareBindings($bindings), $e
    826▕                 );
    827▕             }
    828▕ 
  ➜ 829▕             throw new QueryException(
    830▕                 $this->getName(), $query, $this->prepareBindings($bindings), $e
    831▕             );
    832▕         }
    833▕     }
   
  1   [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(App\Providers\ViewServiceProvider))
   
  2   vendor\laravel\framework\src\Illuminate\Database\Connection.php:423
      PDOException::("SQLSTATE[42S02]: Base table or view not found: 1146 Table 'shozystock.users' doesn't exist")

as i said when i run any command it gives me the same error

#

migration files

#

users code it's the lavavel default code


<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('users');
    }
};
digital trench
#

if your connection is working fine and php artisan migrate:fresh doesn't work, I'd say there is something wrong with the migration. I can't think of anything right now though

bold mason
#

hmm

digital trench
#

I don't remember if the artisan migrate command has a --verbose flag or not, maybe try it and maybe it will give you more info

#

maybe there is some code that queries the user table in you AppServiceProvider or something

#

it is not even booting laravel properly probably

bold mason
#

namespace App\Providers;

use App\Models\Font;
use App\Models\Audio;
use App\Models\Video;
use App\Models\Images;
use App\Models\Vector;
use App\Models\Purchases;
use App\Observers\FontObserver;
use App\Observers\AudioObserver;
use App\Observers\VideoObserver;
use App\Observers\ImagesObserver;
use App\Observers\VectorObserver;
use App\Observers\PurchaseObserver;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Eloquent\Relations\Relation;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Blade::withoutDoubleEncoding();
        Paginator::useBootstrap();

        Relation::enforceMorphMap([
            'photo' => 'App\Models\Images',
            'video' => 'App\Models\Video',
            'vector' => 'App\Models\Vector',
            'audio' => 'App\Models\Audio',
            'font' => 'App\Models\Font',
        ]);

        Purchases::observe(PurchaseObserver::class);
        Images::observe(ImagesObserver::class);
        Vector::observe(VectorObserver::class);
        Video::observe(VideoObserver::class);
        Audio::observe(AudioObserver::class);
        Font::observe(FontObserver::class);
    }
}

all good look

digital trench
#

just to double check, you can delete everything in your boot() function and try to run the migration again

#

but yeah, I don't have a concrete idea of what the problem may be

#

maybe someone else will have a better idea

bold mason
#

yeah bro no problem thanks for your time and appreciate the help

digital trench
#

I'll try running any other artisan command, maybe just php artisan make:migration test_migration or even php artisan tinker

#

because what I suspect is that there is a problem booting laravel

#

because it is trying to query all active users, something that the migrations wouldn't really do, "SQL: select count(*) as aggregate from users where status = active"

bold mason
#

yep same error


   Illuminate\Database\QueryException 

  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'shozystock_db.users' doesn't exist (Connection: mysql, SQL: select count(*) as aggregate from `users` where `status` = active)

  at vendor\laravel\framework\src\Illuminate\Database\Connection.php:829
    825▕                     $this->getName(), $query, $this->prepareBindings($bindings), $e
    826▕                 );
    827▕             }
    828▕
  ➜ 829▕             throw new QueryException(
    830▕                 $this->getName(), $query, $this->prepareBindings($bindings), $e
    831▕             );
    832▕         }
    833▕     }

  1   [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(App\Providers\ViewServiceProvider))

  2   vendor\laravel\framework\src\Illuminate\Database\Connection.php:423
      PDOException::("SQLSTATE[42S02]: Base table or view not found: 1146 Table 'shozystock_db.users' doesn't exist")```
#

   Illuminate\Database\QueryException 

  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'shozystock_db.users' doesn't exist (Connection: mysql, SQL: select count(*) as aggregate from `users` where `status` = active)

  at vendor\laravel\framework\src\Illuminate\Database\Connection.php:829
    825▕                     $this->getName(), $query, $this->prepareBindings($bindings), $e
    826▕                 );
    827▕             }
    828▕
  ➜ 829▕             throw new QueryException(
    830▕                 $this->getName(), $query, $this->prepareBindings($bindings), $e
    831▕             );
    832▕         }
    833▕     }

  1   [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(App\Providers\ViewServiceProvider))

  2   vendor\laravel\framework\src\Illuminate\Database\Connection.php:423
      PDOException::("SQLSTATE[42S02]: Base table or view not found: 1146 Table 'shozystock_db.users' doesn't exist")```
digital trench
#

nice, so now we know it is not something wrong with your migrations, but with your laravel project trying to fetch active users

#

check your ViewServiceProvider?

bold mason
#

namespace App\Providers;

use App\Models\Font;
use App\Models\User;
use App\Models\Audio;
use App\Models\Plans;
use App\Models\Video;
use App\Models\Images;
use App\Models\Report;
use App\Models\Vector;
use App\Models\Deposits;
use App\Models\TaxRates;
use App\Models\Downloads;
use App\Models\Languages;
use App\Models\Categories;
use App\Models\Withdrawals;
use App\Models\AdminSettings;
use App\Models\VerificationRequest;
use Illuminate\Support\ServiceProvider;

class ViewServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
    }

    /**
     * Bootstrap any application services.
     */
    ```
#
    {
        try {
            \DB::connection()->getPdo();
        } catch (\Exception $e) {
            return false;
        }

        $settings = AdminSettings::first();
        $categoriesCount = Categories::count();
        $categoriesMain = Categories::where('mode', 'on')->orderBy('name')->take(5)->get();
        $languages = Languages::orderBy('name')->get();
        $taxRatesCount = TaxRates::whereStatus('1')->count();
        $userCount = User::whereStatus('active')->count();
        $downloadsCount = Downloads::count();
        $imagesCount = Images::whereStatus('active')->count();
        $plansActive = Plans::whereStatus('1')->count();
        $depositsPendingCount = Deposits::selectRaw('COUNT(id) as total')->whereStatus('pending')->pluck('total')->first();
        $withdrawalsPendingCount = Withdrawals::selectRaw('COUNT(id) as total')->whereStatus('pending')->pluck('total')->first();
        $reports = Report::selectRaw('COUNT(id) as total')->pluck('total')->first();
        $verificationRequestsCount = VerificationRequest::selectRaw('COUNT(id) as total')->whereStatus('pending')->pluck('total')->first();

#
        $videosPendingCount = Video::selectRaw('COUNT(id) as total')->whereStatus('pending')->pluck('total')->first();
        $vectorsPendingCount = Vector::selectRaw('COUNT(id) as total')->whereStatus('pending')->pluck('total')->first();
        $audioPendingCount = Audio::selectRaw('COUNT(id) as total')->whereStatus('pending')->pluck('total')->first();
        $fontPendingCount = Font::selectRaw('COUNT(id) as total')->whereStatus('pending')->pluck('total')->first();

        $allItemsPending = ($photosPendingCount + $videosPendingCount + $vectorsPendingCount + $audioPendingCount + $fontPendingCount);

        $allVideos = Video::selectRaw('COUNT(id) as total')->whereStatus('active')->pluck('total')->first();
        $allVectors = Vector::selectRaw('COUNT(id) as total')->whereStatus('active')->pluck('total')->first();
        $allAudio = Audio::selectRaw('COUNT(id) as total')->whereStatus('active')->pluck('total')->first();
        $allFont = Font::selectRaw('COUNT(id) as total')->whereStatus('active')->pluck('total')->first();

        view()->share(compact(
            'settings',
            'categoriesCount',
            'categoriesMain',
            'languages',
            'taxRatesCount',
            'userCount',
            'downloadsCount',
            'imagesCount',
            'plansActive',
            'depositsPendingCount',
            'withdrawalsPendingCount',
            'allItemsPending',
            'photosPendingCount',
            'videosPendingCount',
            'vectorsPendingCount',
            'audioPendingCount',
            'fontPendingCount',
            'allVideos',
            'allVectors',
            'allAudio',
            'allFont',
            'reports',
            'verificationRequestsCount'
        ));
    }
}```
#

Error
SQL query:

SELECT COUNT(*) AS aggregate FROM users WHERE status = 'active' LIMIT 0, 25
MySQL said: Documentation

#1146 - Table 'shozystock_db.users' doesn't exist

digital trench
#

holy

bold mason
#

what?

#

am i gonna die today or what?

digital trench
#

just analyzing the code. Yeah, that will be the problem I think. It is querying the database like crazy but there is no tables, hence the error

#

for now I would just comment everything you think may the the issue (for example, I would comment this whole boot function) and then keep trying to run php artisan tinker

#

once you can do that, then you run your migration and uncomment the code

#

you just got in your hands a very weird project

bold mason
#

php artisan tinker
Psy Shell v0.12.4 (PHP 8.2.12 — cli)

digital trench
#

cool

#

now you can try your migrations and hopefully it will work, php artisan migrate

bold mason
#

nope same error

#

ok i give up

digital trench
#

can you copy and paste it here one more time? I just want to check something. The new error you got when you last ran php artisan migrate

bold mason
#

   INFO  Running migrations.

  2014_10_12_100000_create_password_resets_table .......................................................................................... 3ms FAIL

   Illuminate\Database\QueryException 

  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'password_resets' already exists (Connection: mysql, SQL: create table `password_resets` (`email` varchar(255) not null, `token` varchar(255) not null, `created_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

  at vendor\laravel\framework\src\Illuminate\Database\Connection.php:829
    825▕                     $this->getName(), $query, $this->prepareBindings($bindings), $e
    826▕                 );
    827▕             }
    828▕
  ➜ 829▕             throw new QueryException(
    830▕                 $this->getName(), $query, $this->prepareBindings($bindings), $e
    831▕             );
    832▕         }
    833▕     }

  1   vendor\laravel\framework\src\Illuminate\Database\Connection.php:587
      PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'password_resets' already exists")

  2   vendor\laravel\framework\src\Illuminate\Database\Connection.php:587
      PDOStatement::execute()
digital trench
#

now it is a different error, that is progress

#

if redoing the database is fine, run php artisan migrate:fresh

#

it will delete everything and start over

#

it says there that password_resets already exists and that is throwing an error in the database when trying to create the table

bold mason
#

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#

it works man thank you so much

digital trench
#

no problem, don't forget to uncomment that boot code though