Foreignkey malformed

I have 2 foreign keys, one works and the other gives a malformed error
1.-

public function change(): void
    {
        $refTable = $this->table('bitacora')
            ->addForeignKey('id_bitacora', 'comunidades', 'id_comunidad', ['delete'=> 'CASCADE', 'update'=> 'CASCADE'])
            ->save();
    }

In the botacora table the id has been changed to id_bitacora as follows

$bitacora = $this->table('bitacora',['id' => false, 'primary_key'=> ['id_bitacora']]);
        $bitacora->addColumn('id_bitacora', 'integer', ['null' => false])

2.- This doesn’t work and gives an error:

public function change(): void
    {
        $refTable = $this->table('admins')
            ->addForeignKey('id', 'comunidades', 'id_comunidad', ['delete'=> 'CASCADE', 'update'=> 'CASCADE'])
            ->save();
    }
PDOException: SQLSTATE[HY000]: General error: 1005 Can't create table `servpcspa_syscon`.`admins` (errno: 150 "
Foreign key constraint is incorrectly formed") in /home/servpcspa/web/servpcspa.com/public_html/vendor/robmorga
n/phinx/src/Phinx/Db/Adapter/PdoAdapter.php:203

Sorry I’m not too familiar with FK’s but what might be useful to work to a resolution is running the examples from the docs at Writing Migrations - 0.16 in a test database.

If you install MySQL Workbench and look at the resulting FK’s in the GUI you can then work back to a working migration by comparing the examples in the docs with what they appear as in MySQL Workbench.