Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix the "Base table or view not found: 1146" error when running 'php artisan migrate' command?

I am trying to rum php artisan migrate to generate table migration, but I am getting an error:

[2016-03-08 05:49:01] local.ERROR: exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'testing.permissions' doesn't exist' in D:\xampp\htdocs\LMS-testing\vendor\laravel\framework\src\Illuminate\Database\Connection.php:333

I have tried Base table or view not found: 1146 Table Laravel 5 and Doing a Laravel tutorial, getting "Base table or view not found: 1146 Table 'sdbd_todo.migrations' doesn't exist" but did not succeed.

I have also tried to run php artisan list but getting the same error.

Updated

**RolesPermission migration table**

Schema::create('roles', function(Blueprint $table){
            $table->increments('id');
            $table->string('name')->unique();
            $table->string('label');
            $table->string('description')->nullable();
            $table->timestamps();            
        });
        
        Schema::create('permissions', function(Blueprint $table){
            $table->increments('id');
            $table->string('name')->unique();
            $table->string('label');
            $table->string('description')->nullable();
            $table->timestamps();            
        });
        
        Schema::create('permission_role', function(Blueprint $table){
            $table->integer('permission_id')->unsigned();
            $table->integer('role_id')->unsigned();
            
            $table->foreign('permission_id')
                    ->references('id')
                    ->on('permissions')
                    ->onDelete('cascade');
            
            $table->foreign('role_id')
                    ->references('id')
                    ->on('roles')
                    ->onDelete('cascade');
            
            $table->primary(['permission_id', 'role_id']);
        });
        
        Schema::create('role_user', function(Blueprint $table){
            $table->integer('role_id')->unsigned();
            $table->integer('user_id')->unsigned();
            
            $table->foreign('role_id')
                    ->references('id')
                    ->on('roles')
                    ->onDelete('cascade');
            
            $table->foreign('user_id')
                    ->references('id')
                    ->on('users')
                    ->onDelete('cascade');
            
            $table->primary(['role_id', 'user_id']);
            
        });


.env file
APP_ENV=local
APP_DEBUG=true
APP_KEY=W8YWZe3LCngvZzexH3WLWqCDlYRSufuy

DB_HOST=127.0.0.1
DB_DATABASE=testing
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=log
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
like image 263
Mandy Avatar asked Mar 08 '16 06:03

Mandy


People also ask

How do I fix Sqlstate 42S02 <UNK> base table or view not found 1146 table?

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.

What does PHP artisan migrate do?

php artisan migrate:reset reverses all migration, unlike :rollback . php artisan migrate:fresh is used when we want a fresh or new installation of our database. It deletes all the existing tables of the database and runs the migrate command.


1 Answers

Check your migration file, maybe you are using Schema::table, like this:

Schema::table('table_name', function ($table)  {
    // ...
});

If you want to create a new table you must use Schema::create:

Schema::create('table_name', function ($table)  {
    // ...
});

Laracast More information in this link.

like image 197
Vladimir Salguero Avatar answered Oct 02 '22 20:10

Vladimir Salguero