2013-09-21 168 views
2

我正在嘗試學習Laravel。我正在關注快速入門文檔,但遇到了遷移問題。我在此步驟:http://laravel.com/docs/quick#creating-a-migrationLaravel遷移 - 表未創建

當我運行命令php artisan migrate,命令行顯示如下:

c:\wamp\www\laravel>php artisan migrate 
Migration table created successfully. 
Migrated: 2013_09_21_040037_create_users_table 

在數據庫中,我看到1個紀錄創造了migrations表。但是,我沒有看到users表。所以,我無法繼續學習本教程的ORM部分。

任何想法我可能做錯了什麼?爲什麼不創建users表?

EDIT 1(原遷移文件):

<?php 

use Illuminate\Database\Migrations\Migration; 

class CreateUsersTable extends Migration { 

    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
      Schema::create('users', function($table) 
      { 
       $table->increments('id'); 
       $table->string('email')->unique(); 
       $table->string('name'); 
       $table->timestamps(); 
      }); 
    } 

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

} 

回答

7

更新Laravel應該使用Blueprint數據庫架構創建。 所以試圖改變這樣的用戶遷移文件內容,

<?php 

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

class CreateUsersTable extends Migration { 

    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
     Schema::create('users', function(Blueprint $table) { 
      $table->integer('id', true); 
      $table->string('name'); 
      $table->string('username')->unique(); 
      $table->string('email')->unique(); 
      $table->string('password'); 
      $table->timestamps(); 
      $table->softDeletes(); 
     }); 
    } 

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

} 

然後運行,

php artisan migrate:rollback 

,然後再次遷移。

讀到這裏http://laravel.com/api/class-Illuminate.Database.Schema.Blueprint.html

+1

我無法回退API文檔,因爲如果這是從來沒有在第一時間創建了「用戶」表不能被丟棄。我手動重置數據庫。你的代碼工作。爲什麼呢?我一直在按照教程一步一步。 – StackOverflowNewbie

+0

我認爲,在第一次你沒有寫出創建表的代碼或者放下和關閉函數。它現在工作嗎? – devo

+1

我沒有寫出原始代碼。我只是按照教程中的步驟。我更新了我的問題併發布了原始遷移文件。爲什麼沒有工作?爲什麼你的代碼工作? – StackOverflowNewbie