我是Yii框架的新手。我想在Laravel框架中使用Faker来播种我的数据库。我尝试了这个http://www.yiiframework.com/forum/index.php/topic/59655-how-to-seed-yii2-database/,但是它没有提供太多的细节。如果有人能帮助我完成详细的步骤,我将非常感激。
我是Yii框架的新手。我想在Laravel框架中使用Faker来播种我的数据库。我尝试了这个http://www.yiiframework.com/forum/index.php/topic/59655-how-to-seed-yii2-database/,但是它没有提供太多的细节。如果有人能帮助我完成详细的步骤,我将非常感激。
3条答案
按热度按时间cxfofazt1#
创建控制台命令并在控制台命令控制器中使用Faker来为数据库播种对我来说很有效。
以下是我在commands文件夹下创建的
SeedController.php
文件:并使用
yii seed
命令运行控制器。iaqfqrcu2#
在yii 2-app-advanced测试中可以看到fixtures和faker的实现。在项目中你也可以在控制台中编写
php yii fixture/load
来加载数据库中的种子,以及php yii fixture/generate-all
来生成faker的种子。yii.php
在controllerMap
数组中应该有正确的fixture
控制器:请参阅文档中的详细信息。
au9on6nz3#
如果您不想进行任何验证,而只是将数组传递给自定义控制台命令(如),则也可以使用
batch insert
。并运行它
php yii seed/users
个