forge->addColumn('envios', [ 'cliente_id' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, // IMPORTANTE 'null' => true, 'after' => 'id', ], ]); $this->db->query('ALTER TABLE envios ADD CONSTRAINT fk_envios_cliente FOREIGN KEY (cliente_id) REFERENCES clientes(id) ON DELETE SET NULL ON UPDATE CASCADE'); } public function down() { $this->db->query('ALTER TABLE envios DROP FOREIGN KEY fk_envios_cliente'); $this->forge->dropColumn('envios', 'cliente_id'); } }