QueryException: SQLSTATE [42S02] Базовая таблица или представление не найдены - PullRequest
0 голосов
/ 04 августа 2020

Итак, у меня возникла ошибка при попытке запустить laravel из репозитория github. Там написано SQLSTATE [42502], я пытаюсь решить, глядя на тот же самый topi c, но все же возвращение застряло.

Хронологический порядок такой простой, как этот

  1. Я извлекаю репозиторий из github
  2. Я запускаю composer update, и все пакеты в папке vendors начали устанавливаться один за другим
  3. , пока он не попытается сгенерировать лучшую автозагрузку и появляется ошибка

Кстати, у меня есть только файл миграции базы данных, а не файл. SQL.

Так что, если кто-то из вас может помочь, я очень ценю это. Спасибо

Illuminate\Database\QueryException  : SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel.product_requests' doesn't exist (SQL: select count(*) as aggregate from `product_requests` where `read_at` is null)

  at C:\xampp\htdocs\ayoreview-master\vendor\laravel\framework\src\Illuminate\Database\Connection.php:669
    665|         // If an exception occurs when attempting to run a query, we'll format the error
    666|         // message to include the bindings with SQL, which will make this exception a
    667|         // lot more helpful to the developer instead of just the database's errors.
    668|         catch (Exception $e) {
  > 669|             throw new QueryException(
    670|                 $query, $this->prepareBindings($bindings), $e
    671|             );
    672|         }
    673|

  Exception trace:

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

  2   Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel.product_requests' doesn't exist")
      C:\xampp\htdocs\ayoreview-master\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:66

Мой связанный файл миграции для product_requests

<?php

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

class CreateProductRequestsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('product_requests', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->text('specification');
            $table->bigInteger('price');
            $table->string('link');
            $table->string('featured_image');
            $table->unsignedBigInteger('user_id');
            $table->unsignedBigInteger('category_id')->nullable();
            $table->unsignedBigInteger('brand_id')->nullable();
            $table->text('description')->nullable();
            $table->dateTime('read_at')->nullable();
            $table->dateTime('exported_at')->nullable();
            $table->timestamps();
        });
    }

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

Подробнее

AppServiceProvider

<?php

namespace App\Providers;

use App\ProductRequest;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        if(Config::get('app.redirect_https')) {
            URL::forceScheme('https');
        }
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        if(Config::get('app.redirect_https')) {
            $this->app['request']->server->set('HTTPS', true);
        }

        Paginator::defaultView('custom.pagination');

        $unreadRequestedProduct = ProductRequest::whereNull('read_at')->count();
        session()->flash('product_request', $unreadRequestedProduct);
    }
}

Полная трассировка при выполнении composer обновления

C:\xampp\htdocs\ayoreview-master>composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Updating laravel/framework (v6.18.31 => v6.18.32): Downloading (100%)
Package guzzle/guzzle is abandoned, you should avoid using it. Use guzzlehttp/guzzle instead.
Package jakub-onderka/php-console-color is abandoned, you should avoid using it. Use php-parallel-lint/php-console-color instead.
Package jakub-onderka/php-console-highlighter is abandoned, you should avoid using it. Use php-parallel-lint/php-console-highlighter instead.
Writing lock file
Generating optimized autoload files
Deprecation Notice: Class Guzzle\Tests\Common\Cache\NullCacheAdapterTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Cache\NullCacheAdapterTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Common\AbstractHasAdapterTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Common\AbstractHasDispatcherTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Message\HeaderComparisonTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Http\Message\HeaderComparisonTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Http\Message\HttpRequestFactoryTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Http\Message\RequestFactoryTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Message\ResponseTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Http\Message\ResponseTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Http\CommaAggregatorTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Http\QueryAggregator\CommaAggregatorTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Http\DuplicateAggregatorTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Http\QueryAggregator\DuplicateAggregatorTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Http\PhpAggregatorTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Http\QueryAggregator\PhpAggregatorTest.php
does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Plugin\Redirect\RedirectPluginTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Http\RedirectPluginTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Plugin\Redirect\StaticClientTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Http\StaticClientTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Parsers\UriTemplate\AbstractUriTemplateTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Parser\UriTemplate\AbstractUriTemplateTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Parsers\UriTemplate\PeclUriTemplateTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Parser\UriTemplate\PeclUriTemplateTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Parsers\UriTemplate\UriTemplateTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Parser\UriTemplate\UriTemplateTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Service\ServiceBuilderTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Service\Builder\ServiceBuilderTest.php
does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Service\Command\AliasFactoryTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Service\Command\Factory\AliasFactoryTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Service\Command\CompositeFactoryTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Service\Command\Factory\CompositeFactoryTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Service\Command\ConcreteClassFactoryTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Service\Command\Factory\ConcreteClassFactoryTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Service\Command\MapFactoryTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Service\Command\Factory\MapFactoryTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Service\Command\ServiceDescriptionFactoryTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Service\Command\Factory\ServiceDescriptionFactoryTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class Guzzle\Tests\Service\Command\VisitorFlyweightTest located in C:/xampp/htdocs/ayoreview-master/vendor/guzzle/guzzle/tests\Guzzle\Tests\Service\Command\LocationVisitor\VisitorFlyweightTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   Illuminate\Database\QueryException  : SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel.product_requests' doesn't exist (SQL: select count(*) as aggregate from `product_requests` where `read_at` is null)

  at C:\xampp\htdocs\ayoreview-master\vendor\laravel\framework\src\Illuminate\Database\Connection.php:669
    665|         // If an exception occurs when attempting to run a query, we'll format the error
    666|         // message to include the bindings with SQL, which will make this exception a
    667|         // lot more helpful to the developer instead of just the database's errors.
    668|         catch (Exception $e) {
  > 669|             throw new QueryException(
    670|                 $query, $this->prepareBindings($bindings), $e
    671|             );
    672|         }
    673|

  Exception trace:

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

  2   Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel.product_requests' doesn't exist")
      C:\xampp\htdocs\ayoreview-master\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:66

  Please use the argument -v to see more details.
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

Composer. json

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.2",
        "ext-gd": "*",
        "ext-imagick": "*",
        "doctrine/dbal": "^2.10",
        "fideloper/proxy": "^4.0",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0",
        "intervention/image": "^2.5",
        "laravel/framework": "^6.2",
        "laravel/sanctum": "^2.3",
        "laravel/socialite": "^4.4",
        "laravel/tinker": "^2.0",
        "league/flysystem-aws-s3-v3": "~1.0",
        "santigarcor/laratrust": "^6.0",
        "yajra/laravel-datatables-oracle": "~9.0"
    },
    "require-dev": {
        "barryvdh/laravel-debugbar": "^3.3",
        "barryvdh/laravel-ide-helper": "^2.7",
        "facade/ignition": "^1.4",
        "fzaninotto/faker": "^1.9.1",
        "laravel/ui": "^1.0",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^3.0",
        "phpunit/phpunit": "^8.0",
        "spatie/laravel-web-tinker": "^1.7"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "files": [
            "app/Helpers/helper.php"
        ],
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "@php artisan ide-helper:generate"
        ]
    }
}

1 Ответ

0 голосов
/ 04 августа 2020

Хорошо, ребята, я думаю, что решил эту проблему, попытавшись сначала принудительно выполнить миграцию, а затем выполнить обновление composer позже. Вы, ребята, были правы, это могло быть вызвано ошибкой при загрузке, поэтому процесс миграции был отложен. Поэтому я просто создаю новую папку fre sh laravel и выполняю миграцию только что там.

Вот мой шаг за шагом

1. create new laravel folder
2. copy & paste database folder from the original repo
3. do migrate
    - if " Error
  Class 'Doctrine\DBAL\Driver\PDOMySql\Driver' not found
    - do composer require doctrine/dbal
4. continue migrate again   
5. copy & paste all the rest of folder & file from the original repo
6. composer install

СДЕЛАНО

Спасибо за все ваши комментарии

...