且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法启动Laravel,我收到“找不到基表或视图"错误

更新时间:2023-11-17 17:59:46

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

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.