Laravel数据迁移
生成数据迁移
php artisan make:migration create_tests_table
新的迁移文件会被放置在 database/migrations 目录中。每个迁移文件的名称都包含了一个时间戳,以便让 Laravel 确认迁移的顺序
生成的迁移文件如下所示
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateLaravelTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('laravel', function (Blueprint $table) {
$table->string('emaileee')->index();
$table->string('tokenee');
$table->timestamp('created_ateee')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('password_resets');
}
}
运行迁移
php artisan migrate
修改表结构
修改迁移文件,运行命令 php artisan migrate:refresh
代码如下所示
class CreateTestTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('test', function (Blueprint $table) {
$table->increments('id');
$table->string('email')->unique();
$table->string('name');
$table->string('testalter');//表新增加字段
$table->string('testSuccess');//表新增加字段
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('test');
}
}