我剛剛瞭解瞭如何使用遷移。我成功地創建了一個表,這個模式:向遷移失敗的數據庫表添加新列 - 無法遷移
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('units', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('description');
$table->timestamps();
});
}
Unfortunattely我錯過了列path
,所以我試圖添加它。首先,我告訴myselfe laravel documentation以瞭解如何添加新列。
從文檔:
在架構門面的表的方法可用於更新現有 表。
我嘗試:
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('units', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('description');
$table->timestamps();
});
Schema::table('units', function (Blueprint $table) {
$table->string('path');
});
}
但是,在執行php artisan migrate
後,我得到Nothing to migrate
。
我在做什麼錯?
好,不過' php artisan migrate:rollback'會從表格中刪除所有已經存在的數據?正確? – Black
@EdwardBlack第一個選項,是的。它將刪除先前遷移中的所有表。如果你不想要的話,請使用第二個選項。 –
我正確的命令'php artisan migrate:rollback'只會從遷移文件執行'down()'方法嗎?如果我只在內部執行'echo'hello''並運行回滾命令,那麼它會在控制檯中顯示'hello',所以我認爲我是正確的。 – Black