1

I installed Yii 2 advanced template. "yii migrate" command in CMD works perfectly with the default MySQL database, it populates the database with the tables migration and user as expected (see step 3 explained here: https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/start-installation.md)

But "yii migrate" doesn't work with the postgresql database. It produces following error message:

error message in command line interface (CMD)

What's wrong, or what is missing? Data tables can be read by the Yii 2 framework if I create them manually (already tested), but migrate command doesn't want to work.

The required pdo extensions for postgresql are out-commented in the php.ini file. The web page requirements.php shows "passed" (no errors or warnings) for PDO PostgreSQL extension.

My db connection configuration in common/config/main-local.php:

 'components' => [
        'db' => [
            'class' => 'yii\db\Connection',
            'tablePrefix' => 'tbl_',
            'dsn' => 'pgsql:host=localhost;port=5432;dbname=mytestdb',
            'username' => 'postgres',
            'password' => 'tuparnix',
            'charset' => 'utf8',
            // see: http://stackoverflow.com/questions/26436024/how-to-set-default-schema-in-yii2
            'schemaMap' => [
                'pgsql'=> [
                    'class'=>'yii\db\pgsql\Schema',
                    'defaultSchema' => 'public' //specify your schema here
                ],
            ], // PostgreSQL
        ],
tuncalik
  • 1,124
  • 1
  • 14
  • 20

2 Answers2

1

Your command line php and your web server php is a different php. You need to out-comment your postgres driver in command-line php.ini. Please run these in command line for more info (I'm not sure what is windows version of these command, please chk)

which php
php -i
chaintng
  • 1,325
  • 3
  • 14
  • 26
  • 1
    Yes, that was it then, thanks. The command is "where php" in windows to find the path of php.exe, which is C:\wamp\bin\php\php5.5.12\php.exe on my machine. I adjusted the php.ini file in the same folder as you suggested, that is, out-commented the lines extension=php_pdo_pgsql.dll and extension=php_pgsql.dll, and "yii migrate" command worked. I am not sure, if php.exe is different for my web server and for my console, but the respective ini files are definitively different. – tuncalik Jul 31 '15 at 11:34
0

I have the same problem in Windows but not Linux. Perhaps, that come from driver php_pdo_pgsql + libpq.dll. Which version you have in your phpinfo (), Postgresql 8.3.3 (windows) or 9.2.1 (linux) that would not be compatible. Looking from this side. What is the server you are using on Windows? (xampp, easyphp, WampServer) and what version of php (5.4, 5.5, 5.6 ...).

tumefaischier
  • 21
  • 1
  • 5