從現有資料庫產生 Laravel 遷移,包括索引和外鍵!
請注意,Laravel 4 Generator 編輯已移至https://github.com/xethron/Laravel-4-Generators.git
以更新相容性。
建議的安裝方法是透過 Composer:
composer require --dev " xethron/migrations-generator "
在 Laravel 5.5 中,服務提供者將自動註冊。
在舊版的框架中,編輯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);
}
// ...
}
筆記:
feature/laravel-five-stable
是從way/generators
3.0.3
分叉出來的,並為 Laravel 5.0
做好了準備。 Jeffrey Way 已停止對 Laravel 5 的支持,因此其他artisan generate:
命令可能尚未與5.0
相容。研究artisan make:
替代品的命令,為 Laravel 做出貢獻以擴展生成支持,或修復它並向jamisonvalenta/feature/laravel-five-stable
提交 PR。 執行以下作曲家命令:
composer require --dev " xethron/migrations-generator:~1.3.0 "
接下來,新增以下服務提供者:
' WayGeneratorsGeneratorsServiceProvider ' ,
' XethronMigrationsGeneratorMigrationsGeneratorServiceProvider ' ,
你就準備好了。若要仔細檢查是否正常運作,請執行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 遷移產生器的變更日誌
感謝 Jeffrey Way 提供的令人驚嘆的 Laravel-4-Generators 包。這個包很大程度上取決於他的工作。
伯恩哈德·布雷滕巴赫 (@BBreyten)
Laravel Migrations Generator 是根據 MIT 許可證授權的開源軟體