接盘侠必备 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专员在静静的抄你码
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

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