简体   繁体   English

QueryException: SQLSTATE[42S02] 未找到基表或视图

[英]QueryException : SQLSTATE[42S02] Base table or view not found

So I have an error while try to run laravel from my github repo.所以我在尝试从我的 github 存储库运行 laravel 时出错。 It says SQLSTATE[42502], I try to solve by looking the same topic, but still, comeback stuck.它说 SQLSTATE [42502],我尝试通过查看相同的主题来解决,但仍然卷土重来。

The chronological order is simple like this时间顺序就这么简单

  1. I pull a repository from github我从 github 中提取了一个存储库
  2. I run composer update and all package in vendors folder started to install one by one我运行 composer update 并且 vendors 文件夹中的所有 package 开始一个一个安装
  3. Until it try to generate best auto-load and the error appears直到它尝试生成最佳自动加载并出现错误

BTW I only have the database migration file and not the.SQL one.顺便说一句,我只有数据库迁移文件,没有 .SQL 文件。

So if anyone of you could help, I really appreciate it.所以如果你们中的任何人能提供帮助,我真的很感激。 Thanks谢谢

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

My related migration file for product_requests我的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');
    }
}

More Detail更多详情

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);
    }
}

Full trace when doing composer update作曲家更新时的完整跟踪

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作曲家.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"
        ]
    }
}

Ok guys, I think I solved this with trying to forced the migration first then do the composer update later.好的伙计们,我想我通过尝试先强制迁移然后再进行作曲家更新来解决这个问题。 You guys were right it caused maybe by the error from something on boot so it postponed the migration process.你们是对的,这可能是由启动时的错误引起的,所以它推迟了迁移过程。 So I just create a new fresh laravel folder and doing the migration freshly there.所以我只是创建了一个新的 laravel 文件夹,并在那里进行了全新的迁移。

Here my step by step这是我一步一步

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

DONE完毕

Thanks for all of your comment感谢您的所有评论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel 查询异常/SQLSTATE[42S02] - Laravel QueryException / SQLSTATE[42S02] 运行迁移时,“ SQLSTATE [42S02]:找不到基表或视图” - “ SQLSTATE[42S02]: Base table or view not found” when running migration SQLSTATE [42S02]:未找到基表或视图:1146 表 'dbs1056212.User_Logs' 不存在 - SQLSTATE[42S02]: Base table or view not found: 1146 Table 'dbs1056212.User_Logs' doesn't exist SQLSTATE [42S02]:未找到基表或视图:1146 表“laravel_abonamenty2.currencies”不存在 - SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel_abonamenty2.currencies' doesn't exist SQLSTATE [42S02]-来自子查询 - SQLSTATE[42S02] - from subquery 错误1109(42S02):MULTI DELETE中的未知表 - ERROR 1109 (42S02): Unknown table in MULTI DELETE QueryException SQLSTATE [42S22]:找不到列:1054 - QueryException SQLSTATE[42S22]: Column not found: 1054 错误1109(42S02):字段列表中的未知表&#39;comment&#39; - ERROR 1109 (42S02): Unknown table 'comment' in field list 导入到我的数据库时出错:第 217004 行的 ERROR 1146 (42S02):表 &#39;caol2.cao_curriculo&#39; 不存在 - Error importing into my database: ERROR 1146 (42S02) at line 217004: Table 'caol2.cao_curriculo' doesn't exist mysql命令行认为我使用的是另一个表。 错误1146(42S02)在第1行 - mysql command line thinks I am using a different table. ERROR 1146 (42S02) at line 1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM