git clone https://github.com/cviebrock/sequel-pro-laravel-export.git
.
然后进入项目目录,双击ExportToLaravelMigration.spBundle
文件,接下来在打开的页面连接到数据库,在左侧选中一张数据表,在菜单栏选择Bundles › Export › Export
将数据表导出为迁移文件(或者使用快捷命令⌃⌥⌘M
):
这样就会将选中数据表转化为 Laravel 数据库迁移文件并存放在桌面,
比如我选中的是users表,对应的迁移文件是2017_09_29_112221_create_users_table.php,文件内容如下:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
/**
* Migration auto-generated by Sequel Pro Laravel Export
* @see https://github.com/cviebrock/sequel-pro-laravel-export
*/
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->integer('role_id')->nullable();
$table->string('name', 255);
$table->string('email', 255);
$table->string('avatar', 255)->nullable()->default('users/default.png');
$table->string('password', 255);
$table->rememberToken();
$table->nullableTimestamps();
$table->unique('email', 'users_email_unique');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
我们可以将其拷贝到 Laravel 项目的数据库迁移目录,以便后续使用该文件进行后续操作。