php artisan make:migration alter_sources_description --table=life_car_sources
php artisan migrate
php artisan migrate:rollback --step=1 # 回滾變更
use IlluminateDatabaseMigrationsMigration;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateSupportFacadesSchema;
/**
* php artisan make:migration alter_sources_description --table=要改的表名稱(chēng)
* php artisan migrate
* php artisan migrate:rollback --step=1 # 回滾變更
*/
class AlterSourcesDescription extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('要改的表名稱(chēng)', function (Blueprint $table) {
DB::statement("ALTER TABLE 要改的表名稱(chēng) MODIFY vehicle_description varchar(1000) default '' NOT NULL COMMENT '車(chē)輛描述';");
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('要改的表名稱(chēng)', function (Blueprint $table) {
DB::statement("ALTER TABLE 要改的表名稱(chēng) MODIFY vehicle_description varchar(255) default '' NOT NULL COMMENT '車(chē)輛描述';");
});
}
}
新增字段
php artisan make:migration add_字段名_to_表名?--table=表名?
use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
class AddPayMethodToOrder extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('表名', function (Blueprint $table) {
$table->tinyInteger("字段名")->default(2)->comment("1-xxx 2-yyyy")->after("前面一個(gè)字段名");
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('表名', function (Blueprint $table) {
$table->removeColumn("字段名");
});
}
}
本文摘自 :https://blog.51cto.com/u