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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25315325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:46:43  来源:igfitidea点击:

Laravel: Base table or view not found: 1146 Table 'database.pages doesn't exist

phplaravelmigrate

提问by bobbybouwmann

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:

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

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...

但这显示了同样的错误......

回答by Jeff Lambert

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:

从这些文件中删除所有从模型中请求数据的行,以确保 artisan 不会尝试从不存在的表中加载数据:

  • bootstrap/start.php
  • app/start/global.php
  • app/start/local.php
  • app/routes.php
  • 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.

还要确保取消注册任何在其注册或引导方法中使用该表中数据的服务提供者app/config/app.php



The issue is that these files not only get executed for browser (web) requests, but for allrequests, 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.

问题是这些文件不仅会针对浏览器(Web)请求执行,还会针对所有请求执行,包括命令行工匠调用(例如php artisan migrate)。因此,如果您在这些文件中的任何一个可用之前尝试使用某些内容,那么您将度过一段糟糕的时光。

回答by Emeka Mbah

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

这样您就可以防止从不存在的表中加载数据