liudaved/ migrations-generator
从现有数据库生成 Laravel 迁移
Requires
- php: >=7.2.0
- doctrine/dbal: ~2.4
- illuminate/support: ~6.0
- liudaved/laravel-4-generators: ~4.0.0
Requires (Dev)
- illuminate/cache: >=4.1.0
- illuminate/console: >=4.1.0
- mockery/mockery: >=0.9.0
- phpunit/phpunit: >=4.0.0
README
从现有数据库生成 Laravel 迁移,包括索引和外键!
升级到 Laravel 5.4
请注意,Laravel 4 生成器的编辑已移动到 https://github.com/xethron/Laravel-4-Generators.git
以更新兼容性。
Laravel 5 安装
推荐通过 composer 安装此软件
composer require --dev "xethron/migrations-generator"
In Laravel 5.5 the service providers will automatically get registered.
In older versions of the framework edit config/app.php
and add this to providers section
Way\Generators\GeneratorsServiceProvider::class, Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider::class,
If you want this lib only for dev, you can add the following code to your app/Providers/AppServiceProvider.php
file, within the register()
method
public function register() { if ($this->app->environment() !== 'production') { $this->app->register(\Way\Generators\GeneratorsServiceProvider::class); $this->app->register(\Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider::class); } // ... }
备注
- 感谢 @jamisonvalenta,现在您可以在 Laravel 5 中生成迁移了!
feature/laravel-five-stable
从way/generators
3.0.3
分支出来,并已准备好用于 Laravel5.0
。Jeffrey Way 已经停止了对 Laravel 5 的支持,因此其他artisan generate:
命令可能没有与5.0
兼容。调查artisan make:
命令的替代方案,为 Laravel 贡献以扩展生成支持,或修复它并向jamisonvalenta/feature/laravel-five-stable
提交 PR。
Laravel 4 安装
运行以下 composer 命令
composer require --dev "xethron/migrations-generator:~1.3.0"
然后,添加以下服务提供者
'Way\Generators\GeneratorsServiceProvider', 'Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider',
您就绪了。为了检查它是否正常工作,请运行 php artisan
并查找命令 migrate:generate
用法
要从数据库生成迁移,您需要将数据库设置在 Laravel 的配置中。
运行 php artisan migrate:generate
以创建所有表的迁移,或者您可以使用 php artisan migrate:generate table1,table2,table3,table4,table5
指定要生成的表。您还可以使用 --ignore="table3,table4,table5"
忽略表。
Laravel Migrations Generator 将首先生成所有表、列和索引,然后设置所有外键约束。因此,请确保包括外键中列出的所有表,以便在创建外键时它们是存在的。
如果您不是使用默认连接,可以使用 --connection="connection_name"
指定连接名称。
运行 php artisan help migrate:generate
以获取选项列表。
查看 Chung Tran 的博客文章以获取快速分步介绍: 在 Laravel 4 中从现有数据库生成迁移
变更日志
Laravel Migrations Generator 的变更日志
2016年11月20日:v2.0.0
- Laravel 5 支持
2016年11月20日:v1.3.0
- 添加选项 --defaultIndexNames 和 --defaultFKNames 以使用 Laravel 的默认生成的名称
- 支持 --no-interaction
- 迁移表字段注释
- 如果不是默认连接,将连接添加到迁移中
- 错误修复
- --ignore 不忽略列表中的第一个表
- 从索引名称中删除反引号 #17
- 删除使用错误键名的外键 #34
- 从迁移中删除表前缀
- 转义表名和参数
- 将 JSON 列映射为文本
- 布尔默认值为空字符串
2016年7月25日:v1.2.2
- Laravel 4.2 支持
- 支持命名外键
- 修复了 --ignore 选项的错误
2016年5月29日:v1.2.1
- 修复了 char 字段显示为 varchar 的问题
- 允许 decimal、float 和 double 为无符号
- 允许外键更新/删除时的级联
2016年5月16日:v1.2.0
- 现在完全支持 enum 字段
- 将位字段作为布尔值支持(Laravel 迁移限制)
2016年5月10日:v1.1.1
- 修复迁移使用枚举的表时的崩溃问题
- 添加了测试
- 对代码进行重大重构
3月24日:v1.1.0
- 能够向迁移表添加条目,这样它们就不会被执行,因为它们已经存在。
- 将Blobs转换为二进制字段
- 少量代码更改
谢谢
感谢Jeffrey Way及其惊人的Laravel-4-Generators包。本包在很大程度上依赖于他的工作。
贡献者
Bernhard Breytenbach (@BBreyten)
许可证
Laravel迁移生成器是开源软件,采用MIT许可证。