Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined property: stdClass::$column_name when generating a model #20190

Closed
metaodi opened this issue Jul 20, 2017 · 9 comments
Closed

Undefined property: stdClass::$column_name when generating a model #20190

metaodi opened this issue Jul 20, 2017 · 9 comments

Comments

@metaodi
Copy link

metaodi commented Jul 20, 2017

  • Laravel Version: 5.1
  • PHP Version: 7.1
  • Database Driver & Version: mysqlnd 5.0.12-dev

Description:

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 = ?

Steps To Reproduce:

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: rainlab/builder-plugin#161

@geekjam
Copy link

geekjam commented Jul 23, 2017

In Laradock:
laradock1
In Debian Mysql Server
debian-mysql-server

@hubertursua
Copy link

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 ...

@Desseres
Copy link

@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')

@themsaid themsaid closed this as completed Sep 5, 2017
@laurenkt
Copy link
Contributor

laurenkt commented Sep 6, 2017

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.

@metaodi
Copy link
Author

metaodi commented Sep 6, 2017

@themsaid why did you close this? Shouldn't the fix mentioned above by @Hyubs be implemented?

@themsaid
Copy link
Member

themsaid commented Sep 6, 2017

@metaodi feel free to open a PR

laurenkt added a commit to laurenkt/framework that referenced this issue Sep 6, 2017
@laurenkt
Copy link
Contributor

laurenkt commented Sep 6, 2017

Opened a PR #21037

@laurenkt
Copy link
Contributor

laurenkt commented Sep 6, 2017

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.

gonzahce added a commit to gonzahce/framework that referenced this issue Sep 6, 2017
*      catch errors as well (laravel#21047)

* return  from Validator::setCustomMessages (laravel#21046)

*       show exception class in JSON (laravel#21043)

* [5.5] Removed listener listensFor (laravel#21039)

* remove listensFor

* remove listensFor

* Specify lower case `column_name` (fixes laravel#20190) (laravel#21037)

* [5.5] Add policies method to Gate (laravel#21036)
prinsss added a commit to prinsss/blessing-skin-server that referenced this issue Jul 31, 2018
prinsss added a commit to prinsss/blessing-skin-server that referenced this issue Sep 23, 2018
stuheiss added a commit to stuheiss/migrations-generator that referenced this issue Feb 4, 2019
Querying information_schema.columns returns upper cased column names on
some versions of mysqld. This is similar to an old bug in
laravel/framework. See laravel/framework#20190

Fix by changing
    select column_name, column_type ...
to
    select column_name as column_name, column_type as column_type ...
@loren-garcia
Copy link

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 ...

Totally works! Thanks"

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

No branches or pull requests

7 participants