使用迁移来插入或更改表结构对我来说没有问题.但是,我有一个问题是使用模型更改表中的数据.我的想法是做那样的事情:
public function up()
{
$models = MyModel::model()->findAll();
foreach ($models as $variable) {
$variable->property = str_replace('.', ',', $variable->property);
$variable->save();
}
}
Run Code Online (Sandbox Code Playgroud)
看来,我无法导入模型,因为我遇到了以下错误:
*** applying m111010_084827_convert_point_2_comma
PHP Error[2]: include(MyModel.php): failed to open stream: No such file or directory
Run Code Online (Sandbox Code Playgroud)
如果我之前尝试导入模型:
$modelClass = Yii::import('application.models.*');
Run Code Online (Sandbox Code Playgroud)
然后错误是:
*** applying m111010_084827_convert_point_2_comma
exception 'CDbException' with message 'The table "{{mymodel}}" for active record class "MyModel" cannot be found in the database.' in C:\...\yii\framework\db\ar\CActiveRecord.php:2276
Run Code Online (Sandbox Code Playgroud)
问题出在哪儿?我究竟做错了什么?我该如何以正确的方式导入迁移模型?或者我可能应该用SQL命令替换字符串?