SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel8.projects' doesn't exist

Created at 09-Apr-2021 , By samar

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel8.projects' doesn't exist

In this session, we are going to try to solve the "SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel8.projects' doesn't exist" puzzle by using the computer language.

  • SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel8.projects' doesn't exist while using migration command

    --PATH database\migrations\<yourmigrationfile>.php
    public function up()
    {
        //Schema::table('projects', function (Blueprint $table) {
        Schema::create('projects', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->timestamps();
        });
    }
    

    SQLSTATE[42S02]: Base table or view not found: 1146 Table is the most common error while migrating the table in laravel. Update your migration file instead of Schema::table('projects', function (Blueprint $table) use Schema::create('projects', function (Blueprint $table) in your migration file. There could be any reason for this error but in my case we got the solution using create() method instead of table() method. 

    The table method on the Schema facade may be used to update existing table structure. But create method is used to create the new table structure which is not already exist. The Schema::table method is used to modify an existing table, use Schema::create to create new one.

Back to code snippet queries related laravel

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.