SQLSTATE[42S02]: Base table or view not found: 1146 Table

Posted 6 days ago by chrisgrim

I have rolled back all my migrations so there is nothing in my table. When I try to do anything with php artisan (even just php artisan tinker) I am getting the error

In Connection.php line 664:

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


In Connection.php line 326:

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

I tried connecting to a new database but still getting the error. I do have the migration file for category

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCategoriesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('categories', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('slug');
            $table->string('name');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('categories');
    }
}

I have even tried to do adjust the categories.php model to name the table

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
  public $table = "categories";
  protected $guarded = [];
  protected $with = ['roundups'];
    public function getRouteKeyName()
    {
        return 'slug';
    }
    public function roundups()
    {
        return $this->hasMany(Roundup::class);
    }
}

I am stuck and don't know how to move forward. I tried deleting all my routes and I am still getting the error. Thanks so much for any help!

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.