已有的数据库需要生成migration迁移文件可以使用此包快速生成迁移文件,包括索引和外键。
Laravel Migrations Generator: Automatically generate your migrations from an existing database schema.
Github地址:https://github.com/Xethron/migrations-generator
composer require --dev "xethron/migrations-generator"
老的版本需要在config/app.php文件中添加如下命令
Way\Generators\GeneratorsServiceProvider::class, Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider::class,
如果只是想要在开发环境中使用此包的话,可以在文件app/Providers/AppServiceProvider.php的register()中添加如下代码
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"
宠物免费领养小程序,欢迎来踩