无法启动Laravel,我收到“找不到基表或视图"错误 [英] Can't start Laravel, I get "Base table or view not found" error

查看:76
本文介绍了无法启动Laravel,我收到“找不到基表或视图"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我错误地回滚了2次迁移,然后运行了 php artisan migration 命令,但出现以下错误:

First I rolled back 2 migrations by mistake, then I ran php artisan migrate command and I got the following error:

[Illuminate \ Database \ QueryException]SQLSTATE [42S02]:找不到基表或视图:1146表'exercise1.categories'不存在(SQL:select * from类别,其中 parent_id = 0)[PDOException]SQLSTATE [42S02]:找不到基表或视图:1146表'exercise1.categories'不存在

[Illuminate\Database\QueryException] SQLSTATE[42S02]: Base table or view not found: 1146 Table 'exercise1.categories' doesn't exist (SQL: select * from categories where parent_id = 0) [PDOException] SQLSTATE[42S02]: Base table or view not found: 1146 Table 'exercise1.categories' doesn't exist

然后我停了Laravel.之后,当我运行 php artisan serve 命令启动Laravel时,出现了同样的错误.这是我已回滚的2项迁移:

Then I stopped Laravel. After that when I run the php artisan serve command for starting Laravel I get the same error. Here are 2 migrations which I've rolled back:

1.

class CreateCategoriesTable extends Migration
    {

        public function up()
        {
            Schema::create('categories',function (Blueprint $table){
                $table->increments('id');
                $table->string('name');
                $table->text('parent_id');
                $table->timestamps();
        });
        }
        public function down()
        {
            Schema::dropIfExists('categories');
        }
    }

2.

class CreateArticlesTable extends Migration
    {
        public function up()
        {
            Schema::create('articles', function (Blueprint $table) {
                $table->increments('id');
                $table->string('title')->nullable(false);
                $table->longText('article')->nullable(false);
                $table->integer('user_id')->unsigned();
                $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
                $table->timestamps();
            });
        }
        public function down()
        {
            Schema::dropIfExists('articles');
        }
    }

请帮助我解决这个令人沮丧的问题.非常感谢所有答案,在此先感谢.

Please help me to solve this frustrating problem. All answers are highly appreciated, thanks in advance.

推荐答案

如果遇到此问题,并且不是由迁移文件引起的,则很可能是由于两个可能的原因而发生的.

If you encounter with this problem and if it's not caused by migration files then most probably it happens because of 2 possible reasons.

  1. 检查 ServiceProviders 的启动功能,如果它包含查询不存在的表的查询.
  2. 检查是否已创建自定义帮助程序功能,并将该帮助程序功能自动加载到composer.json文件中.如果自定义帮助程序函数包含的查询正在查询不存在的表,则会导致此错误.
  1. Check ServiceProviders' boot function if it contains queries that are querying tables that don't exist.
  2. Check if you've created custom helper function and autoloaded that helper function in composer.json file. If custom helper function contains queries that are querying tables that don't exist it will cause this error.

由于在laravel启动时首先加载了ServiceProviders的启动功能和自动加载的自定义帮助程序功能,所以所有 php artisan 命令都会生成未找到基本表或视图".错误.

Since ServiceProviders' boot functions and autoloaded custom helper functions are loaded first when laravel is started all the php artisan commands will generate "Base table or view not found" error.

这时,您应该做的是注释掉那些查询不存在的表并运行 php artisan serve 的查询,然后运行 php artisan migrate .然后取消注释这些行,保存并一切正常.

At this point what you should do is comment out those queries that are querying nonexistent tables and run php artisan serve then run php artisan migrate. Then uncomment those lines, save it and everything should work fine.

正如@devk所建议的那样,最好检查laravel日志文件,该文件准确指出问题发生的位置.这使我找到了解决方案.为此,请不要忘记打开调试模式.

As @devk suggested it's better to check laravel log files which points exactly to where the problem happens. It led me to find a solution. For this don't forget to Turn on debug mode.

这篇关于无法启动Laravel,我收到“找不到基表或视图"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆