You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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'.
The text was updated successfully, but these errors were encountered:
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?
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 withThere 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 thegetColumnType
definition to find out why this was happening.Steps To Reproduce
posts
) containing a column with any name (e.g.id
).Schema::getColumnType('posts', 'id')
. It will return the column type.Schema::getColumnType('posts', 'ID')
. It will throw anInvalidArgumentException
with the messageThere is no column with name 'ID' on table 'posts'
.The text was updated successfully, but these errors were encountered: