What do I need to load DB Config for Migrations?

I am getting an error loading a database configuration. I created my project on my own without the Phalcon DevTools.

So I adjusted my project to include a .phalcon file to be able to run commands, and added a /config/config.php with the code below..

$ [email protected]:/vagrant/www$ sudo phalcon migration generate

Phalcon DevTools (1.3.1)  Error: Cannot load database configuration


$config = new \Phalcon\Config([
'database' => [
'adapter'     => 'Mysql',
'host'        => 'localhost',
'username'    => 'root',
'password'    => '',
'dbname'      => 'jream'
 ]
]);

I do not use a config/loader.php or config/services.php, I do everything in the public/index.php -- is this the cause of the problem?



32.5k

Hey

You try add folder .phalcon in app

    |rootapp/
        |--------- .phalcon     
        |---------app
                    |---config

Hey,

I have a .phalcon file (sometimes its a folder) it seems to make no difference that I can tell. If I do not have that file I cannot run the phalcon devtools at all. But once I add it it does run the tool, it just can't find my config for SQL i think.

I have: /app/config/config.php -- I suppose I might need to dig into the devtools source to see if I can find what exactly it looks for to know about MySQL.



961

I had the same issue except I AM using config/loader.php and config/services.php.

In my case it seems like Devtools does not use the projects dependency injection. I'm setup with multiple databases, so they were uniquely named in the config. Changing the name back to database seemed to fix it (so now I actually have cloned the database settings just for Devtools).

    $config = new \Phalcon\Config([
        'database' => [                    // this should not be necessary
            'adapter'     => 'Mysql',
            'host'        => 'localhost',
            'username'    => 'root',
            'password'    => '',
            'dbname'      => 'admin_db'
        ],
        'masterdb' => [                    // desired database config name
            'adapter'     => 'Mysql',
            'host'        => 'localhost',
            'username'    => 'root',
            'password'    => '',
            'dbname'      => 'admin_db'
        ],
        'slavedb' => [                     // desired database config name
            //...
        ],
        //...
    ]);


443
edited Jan '16

Phalcon devtool usually looks for both config.ini and config.php files. May be the problem is because you have such structure of config.php

<?php
$settings = array(..
);

Then, you should use another one:

<?php
return array(..
);

and if so, change index.php accordingly.

Yes. fix

<?php 
return new Phalcon\Config([

// config... array...

]);