yiic migrate gives CDbException "could not find driver"

Hi,

I have been trying to create and execute the migration class for a database upgrade that I am trying for the first time. In the command prompt, I have been able to create the class file using the command :


yiic migrate create add_column_user

But when I run the command to upgrade the database,


yiic migrate

I get the following error on the console.


exception 'CDbException' with message 'CDbConnection failed to open the DB connection: could not find driv

er' in F:\wamp\www\yii\framework\db\CDbConnection.php:364

Stack trace:

#0 F:\wamp\www\yii\framework\db\CDbConnection.php(313): CDbConnection->open()

#1 F:\wamp\www\yii\framework\db\CDbConnection.php(291): CDbConnection->setActive(true)

#2 F:\wamp\www\yii\framework\base\CModule.php(372): CDbConnection->init()

#3 F:\wamp\www\yii\framework\cli\commands\MigrateCommand.php(415): CModule->getComponent('db')

#4 F:\wamp\www\yii\framework\cli\commands\MigrateCommand.php(423): MigrateCommand->getDbConnection()

#5 F:\wamp\www\yii\framework\cli\commands\MigrateCommand.php(448): MigrateCommand->getMigrationHistory(-1)


#6 F:\wamp\www\yii\framework\cli\commands\MigrateCommand.php(75): MigrateCommand->getNewMigrations()

#7 [internal function]: MigrateCommand->actionUp(Array)

I have checked that PDO Mysql is installed, as I can see the module pdo_mysql by running the command


php -m

I can also connect to the mysql server from the command prompt.

Can anyone help me out what am I missing here?

Thanks!

Kunal

Found the problem. I had not configured the database component for the console in /protected/config/console.php

Thank you! The yii-user extension does not tell to configure the DB in console!!!

Hi guys! i’m having some similar problems. I’m trying the ‘first application’ tutorial and, when I execute ‘>> model User’ in yiic console I get this error:


exception 'CDbException' with message 'CDbConnection failed to open the DB connection: could not find driver' in /opt/lampp/htdocs/yii/framework/db/CDbConnection.php:381

Stack trace:

#0 /opt/lampp/htdocs/yii/framework/db/CDbConnection.php(330): CDbConnection->open()

#1 /opt/lampp/htdocs/yii/framework/db/CDbConnection.php(308): CDbConnection->setActive(true)

#2 /opt/lampp/htdocs/yii/framework/base/CModule.php(387): CDbConnection->init()

#3 /opt/lampp/htdocs/yii/framework/base/CApplication.php(438): CModule->getComponent('db')

#4 /opt/lampp/htdocs/yii/framework/cli/commands/shell/ModelCommand.php(259): CApplication->getDb()

#5 /opt/lampp/htdocs/yii/framework/cli/commands/ShellCommand.php(128): ModelCommand->run(Array)

#6 /opt/lampp/htdocs/yii/framework/cli/commands/ShellCommand.php(99): ShellCommand->runShell()

#7 /opt/lampp/htdocs/yii/framework/console/CConsoleCommandRunner.php(67): ShellCommand->run(Array)

#8 /opt/lampp/htdocs/yii/framework/console/CConsoleApplication.php(91): CConsoleCommandRunner->run(Array)

#9 /opt/lampp/htdocs/yii/framework/base/CApplication.php(169): CConsoleApplication->processRequest()

#10 /opt/lampp/htdocs/yii/framework/yiic.php(33): CApplication->run()

#11 /opt/lampp/htdocs/yii/testdrive/protected/yiic.php(7): require_once('/opt/lampp/htdo...')

#12 {main}

As kunalroy says, I tried o configure the protected/config/console.php file exactly like the main.php. Now they look like this:

protected/config/main.php :




'db'=>array(

			'connectionString' => 'sqlite:protected/data/testdrive.db',

and /protected/config/console.php :


// application components

	'components'=>array(

		'db'=>array(

			'connectionString' => 'sqlite:protected/data/testdrive.db',

		),

I don’t know if I’m missing something, I did exactly as the tutorial says, server is working, php is working and the application can be succesfully accesed via localhost. Btw, I’m working in Ubuntu 12.10.

Thanks!!

p.s.: sorry for my english, still working on that too :)

This problem arise becuase i you have not congigure datbase connection for console.

Open your console.php (protected/config/console.php)

//uncomment the following to use a MySQL database

‘db’=>array(

		'connectionString' => 'mysql:host=localhost;dbname=testdrive',


		'emulatePrepare' => true,


		'username' => 'root',


		'password' => '',


		'charset' => 'utf8',


	),

Your can set your detail or simpy copy from main.php and replace wit it.