如何在Yii种子?

And*_*rew 4 migrate seed yii

我想知道一旦用迁移创建了一个表,怎么能在Yii中播种?我有一个使用up方法的迁移:

    public function up()
{
    $this->createTable('users',array('id'=>"pk",
        'login'=>'string NOT NULL'));
    echo "table 'users' is created.\n";
    return true;
}
Run Code Online (Sandbox Code Playgroud)

我有相应的用户模型及其CRUD操作.当我尝试使用up方法执行另一次迁移时

public function up()
{
   $user = new Users;
   $user->login = "Bob";
   return $user->save();
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误: PHP错误[2]:include(users.php):无法打开流:文件MyYiiRoot\yii\framework\YiiBase.php第421行没有这样的文件或目录

我已经设法通过使用查询构建器(通过插入命令)来实现所需的结果,但我希望有一个更好的出路.

jma*_*phy 5

使用

public function safeUp()
{
   $this->insert('users',array(
      'login'=>'Bob'));
}
Run Code Online (Sandbox Code Playgroud)

您还可以执行更新,删除和许多其他操作.请访问http://www.yiiframework.com/doc/api/1.1/CDbMigration了解更多信息