Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming column with postgreSQL in a migration

I try to rename a column in a migration:

\Schema::table('invitations', function (Blueprint $table) {
    $table->renameColumn('service_id', 'project_id');
});

Running this result in an error:

Unknown database type jsonb requested, Doctrine\DBAL\Platforms\PostgreSQL92Platform may not support it.

My table as a jsonb column, I think it's the problem but I don't know why this problem occurs (because service_id is not a jsonb column).

How can I rename my column? (and why does it not work with what I wrote?)

like image 228
rap-2-h Avatar asked Mar 03 '26 16:03

rap-2-h


1 Answers

I wrote similar migration for MySQL, IMHO, no difference with Psql. The function renameColumn() works only with Doctrine\DBAL` and I didn't wanted to add this dependency to our project. So I did it like that

DB::transaction( function () {
    DB::raw('ALTER TABLE invitations RENAME COLUMN service_id TO project_id');
});

Sorry for my English.

like image 157
maches Avatar answered Mar 06 '26 07:03

maches



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!