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

Schema::getColumnType expects given column name to be lowercase #51429

Closed
DeffiDeffi opened this issue May 16, 2024 · 3 comments
Closed

Schema::getColumnType expects given column name to be lowercase #51429

DeffiDeffi opened this issue May 16, 2024 · 3 comments

Comments

@DeffiDeffi
Copy link

Laravel Version

11.7.0

PHP Version

8.3

Database Driver & Version

No response

Description

When calling Schema::getColumnType on a column that does not follow conventions and contains capital letters, the function will fail with There is no column with name X. Instead, you'll have to pass the column name in lower letters.

Now, an easy fix is to run the column name through strtolower but the error message is not really descriptive and I had to dive into the getColumnType definition to find out why this was happening.

Steps To Reproduce

  • Create a table (e.g. posts) containing a column with any name (e.g. id).
  • Call Schema::getColumnType('posts', 'id'). It will return the column type.
  • Now call Schema::getColumnType('posts', 'ID'). It will throw an InvalidArgumentException with the message There is no column with name 'ID' on table 'posts'.
@driesvints
Copy link
Member

What's your database driver and version?

@DeffiDeffi
Copy link
Author

DeffiDeffi commented May 16, 2024

I'm using Laravel's sqlsrv driver with Microsoft's PHP extension v5.12.0.

I don't think this is a driver issue, though -- in this line of the Schema builder the given column name is identity checked against a lower-cased column name fetched from the database. Would a strtolower on the $column variable break something on other drivers?

@driesvints
Copy link
Member

Someone sent in a PR for this one. Thanks!

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

No branches or pull requests

2 participants