I may have worked myself into a corner on this. Would love feedback.
In a lot of our migrations, we use the class itself and not insert() to add records. There are a couple of reasons for this, including it was easier if we want to populate a uuid column when saving to the db.
This hasn’t caused any issues until recently.
When we test a branch, we do a migrate/fresh and work through any migration issues. Fine. But a recent change to a model has impacted an OLD migration file. In production, this in theory won’t cause issues since that migration is a few months ago. But it totally bombs a migrate/fresh, and so we have a QA issue.
The real solution may be to stop creating records in migrations via the class itself, but I’m not clear how to populate the uuid field easily if I do that.
But, currently, the issue remains that an old migration is breaking.
Here is what happened.
I added a new column ‘sync_enabled’. In my base model, I now have this:
public function rules() {
return [
...
[['sync_enabled'], 'boolean'],
[['uuid'], 'string', 'max' => 36],
[['name', 'name_field'], 'string', 'max' => 255],
[['name'], 'unique'],
...
];
}
When I do a migrate/fresh, I now get this:
Exception 'yii\base\UnknownPropertyException' with message 'Getting unknown property: common\models\base\PsaEntityType::sync_enabled'
in .../vendor/yiisoft/yii2/base/Component.php:155
If I delete the “sync_enabled boolean” rule in the base model, the migrate/fresh works fine again. So it is definitely related to that new column being there.
The old migration just does a loop like so:
foreach ($list as $item) {
$model = PsaEntityType::find()->...
if (! isset($model)) {
... create
... add new/unrelated column to this issue
$model->save();
}}
else {
$model->newUnrelatedCol = x;
$model->save();
}
}