Skip to content

fix: MariaDB 12 uses numeric foreign keys by default#2413

Open
joshbmarshall wants to merge 1 commit into
cakephp:0.xfrom
joshbmarshall:0.x
Open

fix: MariaDB 12 uses numeric foreign keys by default#2413
joshbmarshall wants to merge 1 commit into
cakephp:0.xfrom
joshbmarshall:0.x

Conversation

@joshbmarshall
Copy link
Copy Markdown
Contributor

MariaDB 12.2 (I think also 12.1) if you do not specify a foreign key name, will use numeric strings ("1", "2", "3" etc)

When you go to drop a foreign key, it puts the constraint name as the key in the array. PHP sees it as a numeric string and changes it to an int.

So e.g. the following would previously fail, with an error that $constraint should be a string, int given:

<?php

final class LmsWithdrawalByTeacher extends \Phinx\Migration\AbstractMigration
{
    public function change(): void
    {
        $this->table('s_class_withdrawal')
            ->addColumn('recorded_by_id', 'integer', [
                'null'  => true,
                'after' => 'date',
            ])
            ->addForeignKey('recorded_by_id', 's_teacher')
            ->update();

        $this->table('s_class_withdrawal')
            ->dropForeignKey('recorded_by_id')
            ->update();
    }
}

Should also fix #924

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dropForeignKey does not allow removal of constraints containing whitespaces

2 participants