For example I have this column named 'lowerCaseColumn' in my database.
I get this error when I run migration.
[Doctrine\DBAL\Schema\SchemaException]
There is no column with name 'lowercasecolumn' on table my_table'.
Situation: You have columns named with CamelCase in your database.
You run migration
Schema::table('my_table', function (Blueprint $table) {
$table->renameColumn('lowerCaseColumn', 'lower_case_column');
Can't replicate, what's your database driver?
@themsaid I use mysql.
@hanachan1026 can't reproduce this using mysql.
@hanachan1026
in your migration you are doing:
lowerCaseColumn
In your error you are getting:
lowercasecolumn
That means the error is elsewhere. You might have named the column as lowercasecolumn but when you are renaming it, you are telling it to rename lowerCaseColumn and therefore it can't find it
@themsaid
@Dylan-DPC Sorry, this was about the different issue, I will now close this.
@hanachan1026 What was the issue?
Hello,
I had the same problem using postgresql
The fix in my case :
Schema::table('my_table', function (Blueprint $table) {
$table->renameColumn('"lowerCaseColumn"', 'lower_case_column');
});
A bit more explanations can be found in doctrine/dbal code :
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) .
' RENAME COLUMN ' . $oldColumnName->getQuotedName($this) . ' TO ' . $column->getQuotedName($this);
And here :
/**
* Gets the quoted representation of this asset but only if it was defined with one. Otherwise
* return the plain unquoted value as inserted.
*/
public function getQuotedName(AbstractPlatform $platform) : string
This means that if you provide the column name without the double quotes, the generated query will be something like ALTER TABLE table RENAME COLUMN lowerCaseColumn TO lower_case_column
In postgresql all identifiers that are not double quoted are transformed to lowercase
By providing the double quotes in camelCase column names you will get a query like ALTER TABLE table RENAME COLUMN "lowerCaseColumn" TO lower_case_column which will take into account the camelcase part during the migration
Hope it can be of help to someone,
Have a nice day
Most helpful comment
Hello,
I had the same problem using postgresql
The fix in my case :
A bit more explanations can be found in doctrine/dbal code :
And here :
This means that if you provide the column name without the double quotes, the generated query will be something like
ALTER TABLE table RENAME COLUMN lowerCaseColumn TO lower_case_columnIn postgresql all identifiers that are not double quoted are transformed to lowercase
By providing the double quotes in camelCase column names you will get a query like
ALTER TABLE table RENAME COLUMN "lowerCaseColumn" TO lower_case_columnwhich will take into account the camelcase part during the migrationHope it can be of help to someone,
Have a nice day