微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 在Codeigniter迁移中添加外键

有人可以帮我添加外键和Codeigniter迁移数据库吗?
这是代码
public function up()
{
    $this->dbforge->add_field(array(
    'ID_PELAYANAN' => array(
    'type' => 'INT','constraint' => 50,'auto_increment' => TRUE
    ),'THBLMUT' => array(
    'type' => 'VARCHAR','constraint' => '6',),'ID_disT' => array(
    'type' => 'VARCHAR','constraint' => '2','ID_AREA' => array(
    'type' => 'VARCHAR','constraint' => '5','ID_RAYON' => array(
    'type' => 'VARCHAR','N_RAYON' => array(
    'type' => 'CHAR','constraint' => '70',));
    $this->dbforge->add_key('ID_PELAYANAN',TRUE);
    $this->dbforge->create_table('pelayanan');
}
public function down()
{
    $this->dbforge->drop_table('pelayanan');
    }
}

我想在此表中将’ID_AREA’,’ID_RAYON’作为Forein Key.我该如何解决这个问题?

这有两种方法可以做到这一点.第一个使用create_table,另一个可以在向现有表添加字段时完成.
$this->dbforge->add_field('CONSTRAINT FOREIGN KEY (id) REFERENCES table(id)');

$this->dbforge->add_column('table',[
    'CONSTRAINT fk_id FOREIGN KEY(id) REFERENCES table(id)',]);

原文地址:https://www.jb51.cc/php/137126.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐