odan/phinx-migrations-generator

foreign keys not getting generated

Closed this issue · 8 comments

Hi there, it worked great, thanks for your work.

I've got an issue, the foreign keys are not getting generated automatically. I checked the example configuration you put on readme but not sure about it.

Any help would be appreciated.

odan commented

Hi @samrahman Could you please provide a small example of the table structure?

yeah sure,
Screen Shot 2019-07-14 at 12 41 30 am

  1. I just added this foreign key associations::org_id => Organisations::id
  2. Than ran phinx-migrations generate

Output:
Comparing schema file to the database.
No database changes detected.

odan commented

By default FK migrations are not enabled.

https://github.com/odan/phinx-migrations-generator#migration-configuration

Is this key enabled in your config file?

'foreign_keys' => true,

Not too sure about the config file, all I use is phinx.yml file? Do I need to create anything else? Where do I put it?

odan commented

Here you find a phinx.php configuration file.

The configuration in phinx.yml should work like this:

paths:
    migrations: /your/full/path
    foreign_keys: true

Thanks, with phinx.php, foreign keys are generated.

I've tried phinx.yml first as you mentioned above, which didn't work unfortunately. Would have been great, as yml is more cleaner.

Having same issue. Setting the

paths:
    migrations: /your/full/path
    foreign_keys: true

in .yml file does not work. Do I net to create a .php file in my root directory and manually change the db parameters? All different environments are set in the yml file so... if I want to do movements on two or more environments, do I have to change the phinx.php file every time?

// Get PDO object
$pdo = new PDO(
    'mysql:host=127.0.0.1;dbname=test;charset=utf8', 'root', '',
    array(
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_PERSISTENT => false,
        PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8 COLLATE utf8_unicode_ci',
    )
);
odan commented

Sorry, my example from above was not correct. The key foreign_keys must be placed like in this example:

paths:
    migrations: '%%PHINX_CONFIG_DIR%%/resources/migrations'
    seeds: '%%PHINX_CONFIG_DIR%%/resources/seeds'

foreign_keys: true

environments: