I had to put in the ‘class’=>‘CDbConnection’, part because it was complaining as follows:
exception 'CException' with message 'Object configuration must be an array containing a "class" element.' in /home/dani/lib/yii-1.1.8.r3324/framework/YiiBase.php:198
…but I didn’t understand why the ‘db’ array didn’t need one.
Moving on, I then tried to do a migration:
./yiic migrate --connectionID=testdb
The result was not quite as desired. The migration tables were created in the dev db and tbl_migration was created in the test db.
Thanks, Ivica, but unless I’m missing something, that would require me to flip it back and forth between doing migrations on dev and test. I’m hoping to avoid that.
I’ve found what I was doing wrong, anyway.
I was doing this in my migrations:
Yii::app()->db->createCommand($sql)->execute();
I know, pretty stupid. Go easy on me.
So I changed it to the following and solved the issue:
But that still had me confused because this is what the CDbMigration.getDbConnection() looks like:
public function getDbConnection()
{
if($this->_db===null)
{
$this->_db=Yii::app()->getComponent('db');
if(!$this->_db instanceof CDbConnection)
throw new CException(Yii::t('yii', 'The "db" application component must be configured to be a CDbConnection object.'));
}
return $this->_db;
}
It’s doing the same thing I was! (That is, assuming the connection component it needs is ‘db’.)
After looking a bit deeper I realized that, yeah, it is, but Yii is smarter than that. The migration class never actually gets the connection itself that way. The $_db property is assigned to it by MigrateCommand.instantiateMigration(). And MigrateCommand has the proper value because it was initialized with it off the --connectionID command line arg.
Whew! A bonehead mistake, sure. But I always like when I walk out of these things understanding more. It was almost worth it.