Created
May 26, 2018 08:25
-
-
Save sola-msr/a1ee4561af19ed7a14b7a502b0234ee8 to your computer and use it in GitHub Desktop.
【Laravel5.4】migration機能を用いたテーブルのカラム名変更方法 ref: https://qiita.com/sola-msr/items/510a5eedb2f83211256b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@vm:~/app$ php artisan make:migration rename_birth_to_birthdate_on_contacts_table --table=contacts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Illuminate\Support\Facades\Schema; | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Database\Migrations\Migration; | |
class RenameBirthToBirthdateOnContactsTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::table('contacts', function (Blueprint $table) { | |
// | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::table('contacts', function (Blueprint $table) { | |
// | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Illuminate\Support\Facades\Schema; | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Database\Migrations\Migration; | |
class RenameBirthToBirthdateOnContactsTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::table('contacts', function (Blueprint $table) { | |
$table->renameColumn('birth', 'birth_date'); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::table('contacts', function (Blueprint $table) { | |
$table->renameColumn('birth_date', 'birth'); | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@vm:~/app$ php artisan migrate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@vm:~/app$ php artisan make:migration --help | |
Usage: | |
make:migration [options] [--] <name> | |
Arguments: | |
name The name of the migration. | |
Options: | |
--create[=CREATE] The table to be created. | |
--table[=TABLE] The table to migrate. | |
--path[=PATH] The location where the migration file should be created. | |
-h, --help Display this help message | |
-q, --quiet Do not output any message | |
-V, --version Display this application version | |
--ansi Force ANSI output | |
--no-ansi Disable ANSI output | |
-n, --no-interaction Do not ask any interactive question | |
--env[=ENV] The environment the command should run under | |
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug | |
Help: | |
Create a new migration file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment