thewahh / thewahh-sample-pkg
从现有数据库生成 Laravel 迁移
Requires
- php: >=5.4.0
- doctrine/dbal: ~2.4
- illuminate/support: >=4.1
- xethron/laravel-4-generators: ~3.1.0
Requires (Dev)
- illuminate/cache: >=4.1.0
- illuminate/console: >=4.1.0
- mockery/mockery: >=0.9.0
- phpunit/phpunit: >=4.0.0
This package is not auto-updated.
Last update: 2024-10-02 10:04:33 UTC
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 的变更日志
20 November 2016: v2.0.0
- 支持 Laravel 5
20 November 2016: v1.3.0
- 添加选项 --defaultIndexNames 和 --defaultFKNames 以使用 Laravel 的默认生成名称
- 支持 --no-interaction
- 迁移表字段注释
- 如果不是默认连接,则将连接添加到迁移中
- 错误修复
- --ignore 不会忽略列表中的第一个表
- 从索引名称中移除反引号 #17
- 删除外键使用错误的键名 #34
- 从迁移中移除表前缀
- 转义表名称和参数
- 将 JSON 列映射为文本
- 布尔默认结果为空字符串
25 July: v1.2.2
- 支持 Laravel 4.2
- 支持命名外键
- 修复 --ignore 选项的错误
29 May: v1.2.1
- 修复字符字段显示为 varchar 的问题
- 允许 decimal、float 和 double 为无符号
- 允许外键更新/删除时级联
16 May: v1.2.0
- 现在完全支持枚举字段
- 支持将位字段作为布尔值(Laravel 迁移限制)
10 月:v1.1.1
- 修复使用枚举的表迁移时的崩溃问题
- 添加了测试
- 代码的重大重构
3 月 24 日:v1.1.0
- 能够将条目添加到迁移表中,这样它们就不会因为已经存在而执行。
- 将 Blob 转换为二进制字段
- 代码的细微更改
谢谢
感谢 Jeffrey Way 的 Laravel-4-Generators 包。此包很大程度上依赖于他的工作。
贡献者
Bernhard Breytenbach (@BBreyten)
许可协议
Laravel 迁移生成器是开源软件,使用 MIT 许可协议许可。