2014-09-19 22 views
0

我是laravel的新手,並嘗試創建下表。下面的代碼是在我的「route.php」文件::在Laravel中創建表格異常

Route::get("userDatabase", function(){ 
    Schema::create("users", function($table){ 
     $table->increments('id'); 
     $table->string('username', 32); 
     $table->string('email', 320); 
     $table->string('password', 60); 
     $table->timestamps(); 
    }); 
}); 

當我訪問http://localhost/laravel/public/userDatabase我得到以下異常:

RuntimeException 
PDOException was thrown when trying to read the session data: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel.sessions' doesn't exist 

在「database.php中」文件中的數據庫配置是正確的,而且沒有任何問題。

我在做什麼錯誤,是什麼導致此異常?

感謝

回答

1

你的問題實際上已經無關,與你的代碼,這是一個問題,因爲你使用的數據庫會話司機沒有爲它創造正確的表,所以當它試圖初始化會話(和讀取最終可能在其中的數據)失敗。

無論是創建缺失的會話表,像這樣的模式:

Schema::create('sessions', function($table) { 
    $table->string('id')->unique(); 
    $table->text('payload'); 
    $table->integer('last_activity'); 
}); 

(把在數據庫遷移並運行它)

或更改您的會話驅動程序的東西,不需要一個數據庫,如file驅動程序。

我建議你也閱讀關於會議的official documentation

+0

或者改爲手動創建表格,請調用'artisan session:table && artisan migrate'讓laravel爲您處理。 – 2014-09-20 13:31:33