phinx
phinx copied to clipboard
Problem foreign key with table name without prefix
Hi I want to connect the foreign key to another table that is not related to the project. What should I do, for example:
phinx config: table_prefix = 'ac_'
table1 : ac_user table2 : core_user
ALTER TABLE `ac_user`
ADD CONSTRAINT `ac_user_user_id` FOREIGN KEY (`user_id`)
REFERENCES `core_user` (`user_id`)
ON DELETE CASCADE ON UPDATE CASCADE
I fixed it as follows Is there a better way?
$this->table("user", ['id' => "user_id",'signed' => false])
->addColumn("mobile", "string", ['limit' => 11])
->addIndex(
'mobile',
[
'unique' => true,
]
)
->create();
$tableAdapter = new TablePrefixAdapter($this->getAdapter());
$prefix = $tableAdapter->getPrefix();
$this->execute("ALTER TABLE `{$prefix}user`
ADD CONSTRAINT `{$prefix}user_user_id`
FOREIGN KEY (`user_id`)
REFERENCES `core_user` (`user_id`)
ON DELETE CASCADE ON UPDATE CASCADE;
");