2

I have a table "products" and "intervals" table. In the table "products" I have a column called "intervals_id" need to create a foreign key to the id of the table "intervals".

I'm using it, but it's not working:

public function up() {    
   $refTable = $this->table('products');
   $refTable->addForeignKey('intervals_id', 'intervals', 'id');
   $refTable->save();    
}

I'm doing something wrong?

floriank
  • 25,546
  • 9
  • 42
  • 66
  • 2
    What exactly is not working? "Not working" is a pretty poor explanation. See http://docs.phinx.org/en/latest/migrations.html#working-with-foreign-keys – floriank Sep 19 '16 at 18:03

1 Answers1

0

Bind the both models

$this->Product->bindModel(
    [
        'belongsTo' => [
            'Interval' => [
                'foreignKey' => 'intervals_id',
            ],
        ],
    ],
    false
);
KARTHI SRV
  • 499
  • 4
  • 20