Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryException: General error: 1 no such table: {table_name} (SQL: select * from "{table_name}") #27018

Closed
ellis22 opened this issue Dec 31, 2018 · 4 comments

Comments

@ellis22
Copy link

ellis22 commented Dec 31, 2018

  • Laravel Version: 5.7
  • PHP Version: 7.2
  • Database Driver: sqlite
  • Database: memory

All testing on PHPUnit was working completely fine. But when I added View::share in AppServiceProvider then all the PHPUnit tests failed.

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")

Please guide me, how can I fix this. Where should I call View::share in Laravel app so, all tests should pass.

@staudenmeir
Copy link
Contributor

staudenmeir commented Dec 31, 2018

It doesn't work because AppServiceProvider::boot() is executed before the database is migrated.

@GrahamCampbell
Copy link
Member

@staudenmeir I think you might have misunderstood the question. The way I understood it, is that @ellis22 doesn't want to move that code to only be in the tests. The solution here will be to use Laravel's view composer feature I think. :)

@GrahamCampbell
Copy link
Member

https://laravel.com/docs/5.7/views#view-composers. If you use '*' for the view, you can ensure your categories variable is available in all views.

@ellis22
Copy link
Author

ellis22 commented Dec 31, 2018

@GrahamCampbell you are right I want to share categories variable in all views. I tried view composer '*' also. But getting same PHPunit error.

Edit: view composer '*' is working. I run the phpunit test before saving AppServiceProvider.
Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants