1 頁 (共 1 頁)

php artisan make:migration add field

發表於 : 2015-11-21 23:14:40
yehlu
http://laravel.com/docs/5.1/migrations

代碼: 選擇全部

php artisan make:migration add_birth_to_users_table --table=users

代碼: 選擇全部

<?php

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

class AddBirthToUsersTable extends Migration {
	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up() {
		Schema::table('users', function (Blueprint $table) {
			//
			$table->date('birth');
		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down() {
		Schema::table('users', function (Blueprint $table) {
			//
			$table->dropColumn('birth');
		});
	}
}

代碼: 選擇全部

vagrant@homestead:~/Code/pda$ php artisan migrate
Migration table created successfully.
Migrated: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_100000_create_password_resets_table
Migrated: 2015_11_21_145415_add_birth_to_users_table
vagrant@homestead:~/Code/pda$ php artisan migrate:status
+------+------------------------------------------------+
| Ran? | Migration                                      |
+------+------------------------------------------------+
| Y    | 2014_10_12_000000_create_users_table           |
| Y    | 2014_10_12_100000_create_password_resets_table |
| Y    | 2015_11_21_145415_add_birth_to_users_table     |
+------+------------------------------------------------+
vagrant@homestead:~/Code/pda$ php artisan migrate:rollback
Rolled back: 2015_11_21_145415_add_birth_to_users_table
Rolled back: 2014_10_12_100000_create_password_resets_table
Rolled back: 2014_10_12_000000_create_users_table
vagrant@homestead:~/Code/pda$ php artisan migrate:status
+------+------------------------------------------------+
| Ran? | Migration                                      |
+------+------------------------------------------------+
| N    | 2014_10_12_000000_create_users_table           |
| N    | 2014_10_12_100000_create_password_resets_table |
| N    | 2015_11_21_145415_add_birth_to_users_table     |
+------+------------------------------------------------+
vagrant@homestead:~/Code/pda$ php artisan migrate
Migrated: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_100000_create_password_resets_table
Migrated: 2015_11_21_145415_add_birth_to_users_table