Laravel migration 逆向生成工具

7 篇文章 0 订阅

laravel migration 逆向生成迁移文件

composer

github

laravel5.8

安装

composer require --dev "xethron/migrations-generator"

配置

1、修改文件 config/app.php,添加相应的服务提供者

'providers'       => [
	//......
    Way\Generators\GeneratorsServiceProvider::class,
    Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider::class,
],

2、修改app/Providers/AppServiceProvider.php,注册服务

public function register()
{
    //......
	if ($this->app->environment() !== 'production') {
	$this->app->register(\Way\Generators\GeneratorsServiceProvider::class);
	$this->app->register(\Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider::class);
	}
}

生成迁移文件

php artisan migrate:generate

生成指定表文件

php artisan migrate:generate table1,table2,table3,table4,table5.

忽略指定表表

php artisan migrate:generate --ignore="table3,table4,table5"

生成文件在database/migrations目录下

查看更多用法

php artisan help migrate:generate

migrate:generate [options] [--] [<tables>]

🔚

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Laravel 使用 Migration 来创建和管理数据库表,使得数据库的管理变得更加简单和高效。 以下是使用 MigrationLaravel 中创建数据库表的步骤: 1. 首先,在命令行中使用 `php artisan make:migration` 命令创建一个 Migration 文件,命令格式如下: ``` php artisan make:migration create_table_name --create=table_name ``` 其中,`create_table_name` 是 Migration 文件名,`table_name` 是要创建的数据库表名。 2. 接着,打开刚刚创建的 Migration 文件,可以看到该文件包含了两个函数:`up()` 和 `down()`。 `up()` 函数用于定义创建数据库表的操作,`down()` 函数用于定义回滚操作。 3. 在 `up()` 函数中,使用 Laravel 提供的 Schema 构建器来定义数据库表的结构,例如: ``` public function up() { Schema::create('users', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('name'); $table->string('email')->unique(); $table->string('password'); $table->timestamps(); }); } ``` 上述代码创建了一个名为 `users` 的数据库表,包含 `id`、`name`、`email`、`password` 和 `timestamps` 等字段。 4. 最后,在命令行中使用 `php artisan migrate` 命令将 Migration 文件中定义的数据库表结构应用到数据库中,命令格式如下: ``` php artisan migrate ``` 执行成功后,可以在数据库中看到新创建的 `users` 数据库表。 以上就是使用 MigrationLaravel 中创建数据库表的步骤。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值