[英]QueryException: General error: 1 no such table: {table_name} (SQL: select * from “{table_name}”)
All testing on PHPUnit was working completely fine. 在PHPUnit上进行的所有测试都可以正常工作。 But when I added
View::share
in AppServiceProvider
then all the PHPUnit tests failed. 但是,当我在
AppServiceProvider
添加View::share
,所有PHPUnit测试都失败了。
AppServiceProvider.php AppServiceProvider.php
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
\View::share('categories', \App\Models\Category::all());
}
}
Error 错误
Illuminate\\Database\\QueryException: SQLSTATE[HY000]: General error: 1 no such table: categories (SQL: select * from "categories")
Illuminate \\ Database \\ QueryException:SQLSTATE [HY000]:常规错误:1没有这样的表:Categories(SQL:select * from“ categories”)
I have already used RefreshDatabase
in my all test. 我已经在所有测试中使用了
RefreshDatabase
。
Please guide me, how can I fix this. 请指导我,我该如何解决。 Where should I call
View::share
in Laravel app so, all tests should pass. 我应该在Laravel应用中的何处调用
View::share
,所以所有测试都应该通过。
This is happening due to the fact that the database doesnt even exists perhaps and provider boot is assuming that database/table its up and running. 发生这种情况的原因可能是数据库甚至不存在,并且提供程序启动假定数据库/表已经启动并正在运行。
Secure it a bit more by wrapping it 通过包裹将其固定得更多
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
if(\Schema::hasTable('categories'){
\View::share('categories', \App\Models\Category::all());
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.