Welcome Guest, Not a member yet? Register   Sign In
Migration Foreign key problem
#2

GruppoDpiTable
id_gruppo and id_dpi must have 'unsigned' => true,


PHP Code:
class GruppoDpiTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type'          => 'INT',
                'unsigned'      => true,
                'auto_increment' => true,
            ],

            'id_gruppo' => [
                'type' => 'INT',
                'null' => false,
                'unsigned' => true,
            ],

            'id_dpi' => [
                'type' => 'INT',
                'null' => false,
                'unsigned' => true,
            ],
            'created_at datetime default current_timestamp',
            'updated_at datetime default NULL',
            'deleted_at datetime default NULL',
        ]);

        $this->forge->addForeignKey('id_gruppo','gruppo','id','NO ACTION','NO ACTION');
        $this->forge->addForeignKey('id_dpi','dpi','id','NO ACTION','NO ACTION');

        $this->forge->addKey('id'true);
        $this->forge->createTable('gruppo_dpi');
      
    
}

    public function down()
    {
        $this->forge->dropTable('gruppo_dpi');
    }

Reply


Messages In This Thread
Migration Foreign key problem - by pippuccio76 - 01-17-2024, 06:07 AM
RE: Migration Foreign key problem - by davis.lasis - 01-17-2024, 11:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB