接盘侠必备 Laravel migration 逆向生成工具

同类型的文章(旧包支持到LV5.6)
031. 逆向 Migration 生成器 ——xethron/migrations-generator

下面这个新包,香的地方是已经支持到 Laravel 9.x

Laravel Migrations Generator

github.com/kitloong/laravel-migrat...

Generate Laravel Migrations from an existing database, including indexes and foreign keys!

This package is cloned from github.com/Xethron/migrations-gene... and updated to support Laravel 5.6 and above, with more features.

Supported Database

Laravel Migrations Generator supports all five Laravel first-party support databases:

  • MariaDB
  • MySQL
  • PostgreSQL
  • SQL Server
  • SQLite

Version Compatibility

Laravel Version
9.x 6.x
8.x 6.x
7.x 6.x
6.x 6.x
5.8.x 6.x
5.7.x 6.x
5.6.x 6.x
5.5 and below github.com/Xethron/migrations-gene...

Install

The recommended way to install this is through composer:

composer require --dev kitloong/laravel-migrations-generator

Usage

To generate migrations from a database, you need to have your database setup in Laravel’s config (config/database.php).

To create migrations for all the tables, run:

php artisan migrate:generate

You can specify the tables you wish to generate using:

php artisan migrate:generate --tables="table1,table2,table3,table4,table5"

You can also ignore tables with:

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

Laravel Migrations Generator will first generate all the tables, columns and indexes, and afterwards setup all the foreign key constraints.

So make sure you include all the tables listed in the foreign keys so that they are present when the foreign keys are created.

You can also specify the connection name if you are not using your default connection with:

php artisan migrate:generate --connection="connection_name"

Squash Migrations

By default, Generator will generate multiple migration files for each table.

You can squash all migrations into a single file with:

php artisan migrate:generate --squash
本作品采用《CC 协议》,转载必须注明作者和本文链接
CV专员在静静的抄你码
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!