1
votes

I'm attempting to run a migration in Laravel 4 but I keep getting the following error:

 [Illuminate\Database\QueryException]  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'ramen.categories  ' doesn't exist (SQL: create table `categories` (`id` int unsigned not null  auto_increment primary key) default character set utf8 collate utf8_unicode_ci)

Oddly, if I change the table name from "categories" to "categoriez" the migration runs successfully.

This is the command I used to create the migration:

php artisan migrate:make create_categories_table --table=categories --create=categories

And this is the actual migration file:



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->increments('id');
        $table->timestamps();

        $table->integer('parent')->unsigned();
        $table->string('category_type');
        $table->string('name');
        $table->string('type');

        $table->index('type');
        $table->index('parent');
        $table->index('name');
    });
}

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

}

Again, I get the error if I run this migration but if I simply change "categories" to "categoriez" the migration runs successfully.

I had a categroies table set up previously which I hadn't set up via a migration. I've dropped this table. I also had a Categories model file which I've deleted. I've dropped all database tables and re-run all migrations and tried running composer dump-autoload (though I'm not sure that would have anything to do with this issue).

Why am I getting this "table not found" error when I attempt to create the categories table?

I've checked this thread which is similar to my problem but has not helped me solve this error: Laravel 4 migrate base table not found

1

1 Answers

1
votes

It turns out this was an issue with MYSQL, not Laravel. I attempted creating a "categories" table directly in PHP MyAdmin and was unable to do so.

Creating an arbitrarily named table, renaming that table to "categories" and then dropping that table, seemed to fix the issue. Afterwards, I was able to successfully run the migration.

https://stackoverflow.com/a/10925588/1043556