skip to Main Content

I changed only user table and add several columns and when I try migrate:refresh it tells me this error message

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'basename.categories' doesn't exist (SQL: select * from `categories`)

how can I fixed it?

I run several commands but all times have same error. I run

php artisan optimize:clear
php artisan migration
php artisan migrate:refresh
php artisan migrate:fresh
php artisan migrate

2

Answers


    1. This error can happen if you didn’t setup database connection variables in .env file. Check the project folder for .env file, if there is no such then create it and copy the contents of .env.example into your new file. Don’t forget to edit DB_USERNAME, DB_PORT, and etc.

    2. Second reason you can’t migrate is you do not have such database, make sure you have your database and the names match for those that you have in your .env file. You can run sql query for showing all databases you have in you mysql server by typing following command

      SHOW DATABASES;

    Login or Signup to reply.
  1. The application will run all providers before the command is actually executed.

    So if your database is empty and you put a query, such as Category::all() in boot method, the query will run before your tables is created.

    To fix it, you can do:

    if (!$this->app->runningInConsole()) {
       $categories = Category::all();
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search