php artisan make:migration add field

http://laravel.com/

http://kejyun.github.io/Laravel-4-Docum ... roduction/
回覆文章
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

php artisan make:migration add field

文章 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
回覆文章

回到「laravel」