2016-03-08 46 views
4

我遇到了很大的問題。我想朗姆酒php artisan migrate生成表遷移,但我得到 [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 錯誤。我曾嘗試過在互聯網上進行搜索,但我沒有得到任何解決方案。Laravel 5移植基礎表或未找到視圖:1146

我也試過Base table or view not found: 1146 Table Laravel 5Doing a Laravel tutorial, getting "Base table or view not found: 1146 Table 'sdbd_todo.migrations' doesn't exist",但我沒有成功。

我也試過運行php artisan list,但我又一次得到相同的錯誤。我不知道爲什麼。請給我解決方案。

更新

**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 
+0

能否請您分享遷移文件的代碼? –

+0

已更新,請檢查。 – Mandy

+0

即使我無法運行php artisan make或任何其他命令。我在創建控制器或模型時遇到同樣的錯誤。 – Mandy

回答

0

我曾經面臨同樣的問題,我想這個問題是不是在你的遷移,但看起來你創建數據庫權限表之前的權限進行檢查。確保你的路線中沒有添加authmiddleware。或註釋掉使用來自config/app.php的權限表的任何服務提供商。最有可能從路線移除authmiddleware直到你產生遷移將解決您的問題

+0

我不使用默認提供者,除了collantic Html。我也刪除了路由中的所有代碼。仍然有相同的錯誤。 – Mandy

+0

在我的情況下,這工作。我不明白爲什麼它會對遷移產生任何影響......遷移引導laravel和檢查代碼? – Goowik

0

讓我們來看看以下錯誤消息:

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

所以表permissions不存在。現在,讓我們看看遷移:

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呼叫正在定義一個外鍵permissions表中看到。

有了這個,我們可以假設Laravel試圖創建這個外鍵,但它想要引用的表不存在。

這通常發生在遷移文件的順序不等於必須創建表的順序時。所以,如果我有我的migrations文件夾按以下順序遷移文件:

2016_10_09_134416_create_permission_role_table 
2016_10_09_134416_create_permissions_table 

他們將在順序執行。但是,如果我知道,在permissionspermission_role dependes,我需要改變它們的文件名中的時間戳來改變自己的立場:

2016_10_09_134415_create_permissions_table 
2016_10_09_134416_create_permission_role_table 

在這種情況下,我已經改變了只從create_permissions_table最後一位,因此會少比從create_permissions_role_table的時間戳。在此之後,不要忘記跑步:

composer dump-autoload 

所以作曲家可以知道你的改變。

0

問題是外鍵已添加,但因爲尚未創建而無法找到該表。

1)使表,而不用外鍵

2)做一個9999_99_99_999999_create_foreign_keys.php文件

3)把有需要的外鍵。使用999..9 .php文件可以確保它在完成表後創建外鍵。

4)你首先添加的表,然後添加外鍵。這將工作。

0

萬一別人運行在此我有同樣的問題,它發生的原因是因爲我已經創建了幾個命令,然後回滾我的數據庫重新運行遷移需要。

爲了解決這個問題,我不得不註釋掉的

protected $commands = [] 

內容的應用程序\控制檯\ Kernel.php文件。

唷!!!! :-)

相關問題