Welcome Guest, Not a member yet? Register   Sign In
How to add column with foreign key within migration?
#4

Yes, you need to use query() method now.

The feature to add keys to existing tables will be implemented in v4.3.0.
See https://github.com/codeigniter4/CodeIgni....rst#forge

PHP Code:
$this->forge->addKey(['category''name'], falsefalse'category_name');
$this->forge->addPrimaryKey('id''pk_actions');
$this->forge->addForeignKey('userid''user''id''''''userid_fk');
$this->forge->processIndexes('actions');
/* gives:
ALTER TABLE `actions` ADD KEY `category_name` (`category`, `name`);
ALTER TABLE `actions` ADD CONSTRAINT `pk_actions` PRIMARY KEY(`id`);
ALTER TABLE `actions` ADD CONSTRAINT `userid_fk` FOREIGN KEY (`userid`) REFERENCES `user`(`id`);
*/ 
Reply


Messages In This Thread
RE: How to add column with foreign key within migration? - by kenjis - 11-20-2022, 04:25 AM



Theme © iAndrew 2016 - Forum software by © MyBB