Skip to content

Yii2 ActiveRecord / Schema does not work with MySQL 8.0.21 any more #18207

@meyergru

Description

@meyergru

What steps will reproduce the problem?

Using any ActiveRecord with a model that has dependencies under MySQL 8.0.21. This was a recent secirity update to Ubuntu 20.04.

What is the expected result?

It should work.

What do you get instead?

I receive an exception like this:

2020-07-31 09:24:46 [134.101.220.23][-][suetptivhkpdscnp5ope59s210][error][yii\base\ ErrorException:8] yii\base\ErrorException: Undefined index: constraint_name in /home /name2ip/dyndns/_protected/vendor/yiisoft/yii2/db/mysql/Schema.php:394
Stack trace:
#0 /home/name2ip/dyndns/_protected/vendor/yiisoft/yii2/db/mysql/Schema.php(394): yii \base\ErrorHandler->handleError()
#1 /home/name2ip/dyndns/_protected/vendor/yiisoft/yii2/db/mysql/Schema.php(126): yii \db\mysql\Schema->findConstraints()
#2 /home/name2ip/dyndns/_protected/vendor/yiisoft/yii2/db/Schema.php(757): yii\db\my sql\Schema->loadTableSchema()
#3 /home/name2ip/dyndns/_protected/vendor/yiisoft/yii2/db/Schema.php(193): yii\db\Sc hema->getTableMetadata()
#4 /home/name2ip/dyndns/_protected/vendor/yiisoft/yii2/db/ActiveRecord.php(435): yii \db\Schema->getTableSchema()

Additional info

Q A
Yii version 2.0.36
PHP version 7.4.3
Operating system Ubuntu 20.04

Analysing the problem, I found that in Schema.pm, function findConstraints(), the array index is used like this after fetching the rows from INFORMATION_SCHEMA:

$row['constraint_name']

Actually, this has always worked up to MySQL 8.0.20. Now, the returned column name is 'CONSTRAINT_NAME', so adressing the hash by the lower-case name throws an exception. After I changed all those references to upper case, it works again. However, this should be fixed in a case-independent way in Yii2. Also, there are other places that are suspicious, like loadTableConstraints().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions