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=要改的表名称
* php artisan migrate
* php artisan migrate:rollback --step=1 # 回滚变更
*/
class AlterSourcesDescription extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('要改的表名称', function (Blueprint $table) {
DB::statement("ALTER TABLE 要改的表名称 MODIFY vehicle_description varchar(1000) default '' NOT NULL COMMENT '车辆描述';");
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('要改的表名称', function (Blueprint $table) {
DB::statement("ALTER TABLE 要改的表名称 MODIFY vehicle_description varchar(255) default '' NOT NULL COMMENT '车辆描述';");
});
}
}
新增字段
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("前面一个字段名");
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('表名', function (Blueprint $table) {
$table->removeColumn("字段名");
});
}
}
本文摘自 :https://blog.51cto.com/u