Welcome Guest, Not a member yet? Register   Sign In
Migration add field and set as foreign key
#3

(02-17-2024, 05:21 PM)kenjis Wrote: See https://codeigniter.com/user_guide/dbmgm...ing-tables

i don't understand, this is another migration

Code:
<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AggiungiCampiCliente extends Migration
{
   
    public function up(){
 
        $fields = [

            'cf' =>  [ 
                                'type' => 'VARCHAR',
                                'constraint' => '16',
                                'null' => false,
                                'default' => 0,
                                'after'=>'nome'
                            ],


            'id_tipo_pagamento' =>  [ 
                                'type' => 'int',
                                'null' => false,
                                'after'=>'cf'
                            ],





        ];

       


        $this->forge->addColumn('clienti', $fields);

        $this->forge->addForeignKey('id_tipo_pagamento', 'tipo_pagamenti', 'id', 'NO_ACTION', 'NO_ACTION');

    }

    public function down()
    {
        $fields = [
            'cf',
            'id_tipo_pagamento'

        ];
        $this->forge->dropColumn('clienti', $fields);
    }

Field are added to table but not foreign key set....
Reply


Messages In This Thread
RE: Migration add field and set as foreign key - by pippuccio76 - 02-27-2024, 05:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB