The MySqlProcessor
assumes that the result from MySQL contains a lowercase column called column_name
.
On my installation, if I run the query from compileColumnListing
of MySqlGrammar
select * from information_schema.tables where table_schema = ? and table_name = ?
The result contains the column COLUMN_NAME
in uppercase.
I don't really know where this is changed. In the driver? Maybe it makes sense to change the query in MySqlGrammar
to ensure the correct case of the result:
select column_name as "column_name" from information_schema.tables where table_schema = ? and table_name = ?
If I try to create a new model using the builder-plugin for OctoberCMS, I get the following error:
"Undefined property: stdClass::$column_name" on line 18 of /var/www/public/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/MySqlProcessor.php
There is already an issue in that repo: https://github.com/rainlab/builder-plugin/issues/161
In Laradock:
In Debian Mysql Server
Also encountered this in Laravel 5.4.28. Environment is PHP 7 and MySQL 8.0 using Laradock.
The fix suggested above by @metaodi worked.
Changed the query found in Illuminate\Database\Schema\Grammars\MySqlGrammar@compileColumnListing
:
select column_name from information_schema.columns ...
...to...
select column_name as `column_name` from information_schema.columns ...
@hyubs Thanks! It works!
PHP 7.0.21, MySQL 8.0.1-dmr
Error: Undefined property: stdClass::$column_name
Example: Schema::connection('mysql2')->hasColumn('pharmacy', 'id')
Is there a solution to this problem that doesn't involve patching something in /vendor
pulled in by composer? Otherwise the patch is going to have to be applied every time the project dependencies are pulled in.
@themsaid why did you close this? Shouldn't the fix mentioned above by @hyubs be implemented?
@metaodi feel free to open a PR
Opened a PR #21037
In the meantime if someone wants to automate patching this in vendor/
the command I used is
sed -i 's/select column_name from information_schema/select column_name as `column_name` from information_schema/g' 'vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php'
I've put this as a post-update-cmd hook in composer.json to apply it automatically.
Most helpful comment
In the meantime if someone wants to automate patching this in
vendor/
the command I used isI've put this as a post-update-cmd hook in composer.json to apply it automatically.