克隆数据库或 运行 sql 动态转储 laravel 4

Clone database or run sql dump on the fly in laravel 4

我在 laravel 4 中有一个大项目,我需要即时创建包含大量表的新数据库。我可以即时创建空数据库,但如何用表填充它?我不能即时使用迁移,因为这个应用程序有很多权限,所以用户不能通过它们。

第一个选项是克隆空数据库(数据为空但有表)。 第二个选项是 运行 sql 即时转储文件。

谁能告诉我该怎么做?

Laravel 提供了通过种子填充数据库的选项。检查 docs

Laravel also includes a simple way to seed your database with test data using seed classes. All seed classes are stored in app/database/seeds. Seed classes may have any name you wish, but probably should follow some sensible convention, such as UserTableSeeder, etc. By default, a DatabaseSeeder class is defined for you. From this class, you may use the call method to run other seed classes, allowing you to control the seeding order.

定义种子后 class。您可以通过命令

为数据库播种
php artisan db:seed

选中此 blog post on how to use seeing and also faker library 以使用真实的测试数据预填充数据库。

如果你不能使用命令行。您可以从您的代码中调用种子命令。检查这个 thread .