Laravel:未找到基表或视图:1146表'database.pages不存在

问题描述:

I'm working on a CMS and I have a little problem with my migrations. I added a new migration file and I wanted to add that one. That didn't work so I ran this bit:

php artisan migrate:reset

After that I ran this bit:

php artisan migrate:install
php artisan migrate

And now I get this error:

{"error":{"type":"Illuminate\\Database\\QueryException","message":"SQLSTATE[42S02]: Base table or 
view not found:1146 Table 'cms.pages' doesn't exist (SQL: select * from `pages`)"

The error kinda tells me that it can't find the database, because that's true.

I also have a command that runs the migrate and I run that one like this:

php artisan app:install

But that shows the same error...

我正在使用CMS,我的迁移有点问题。 我添加了一个新的迁移文件,我想添加一个。 这没用,所以我跑了这个位: p>

  php artisan migrate:reset 
  code>  pre> 
 
 

之后我 跑了这一步: p>

  php artisan migrate:install 
php artisan migrate 
  code>  pre> 
 
 

现在我收到此错误 : p>

  {“error”:{“type”:“Illuminate \\ Database \\ QueryException”,“message”:“SQLSTATE [42S02]:基表或
view 找不到:1146表'cms.pages'不存在(SQL:select * from`page`)“
  code>  pre> 
 
 

错误有点告诉我它可以 找不到数据库,因为那是真的。 p>

我还有一个运行迁移的命令,我运行这样的命令: p>

  php artisan app:install 
  code>  pre> 
 
 

但是显示相同的错误...... p> div>

Remove any lines requesting data from your model from these files to be sure artisan is not trying to load data from your non-existent table:

  • bootstrap/start.php
  • app/start/global.php
  • app/start/local.php
  • app/routes.php

Also be sure to un-register any service providers that utilize data from that table in their register or boot methods inside of app/config/app.php.


The issue is that these files not only get executed for browser (web) requests, but for all requests, including command-line artisan invocations (e.g. php artisan migrate). So if you try to use something before it is available in any of these files, you are going to have a Bad Time.

You can use this to dictate when your app is running from the console. I believe this issue only occurs when you run a command

if( !App::runningInConsole() ){
  //allow laravel-menu to run
}

This way you will prevent data load from your non-existent table