Skip to content

PostgreSQL dropPrimary does not work, if using prefix #42804

Closed
@mihy

Description

@mihy
  • Laravel Version: v9.17.0 (but also the same with any lower version
  • PHP Version: 8.1 (but PHP version does not take affect)
  • Database Driver & Version: PostgreSQL (14.3), but also does not take affect

Description:

I can not drop existing index in my database (PostgreSQL) with standard migration.
The problem persist, if using PostgreSQL and prefix is not empty string.
The problem is in file:

https://github.com/laravel/framework/blob/9.x/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php

Line: 355

It generates index name without prefix.

When primary key index name is generating, it leaves naming for PostgreSQL, even if passing optional parameter $index. Generated SQL is something like:

alter table "prefix_test" add primary key ("id")

and PostgreSQL creates index name: prefix_test_pkey

When executing $table->dropPrimary(), raw sql is:
alter table "prefix_test" drop constraint "test_pkey", it does not add prefix and so migration throws error that:

constraint "test_pkey" of relation "prefix_test" does not exist.

It should generate prefix_test_pkey

Optionally $table->primary() and $table->dropPrimary() allows to pass index name, but PostgresGrammar ignores it.

Steps To Reproduce:

  1. install Laravel
  2. change .env DB_CONNECTION to pgsql
  3. change config/database.php line 75 from 'prefix' => '', to 'prefix' => 'prefix_', (under pgsql)
  4. delete all files from database/migrations
  5. create migration file (php artisan make:migration create_test_table (see below)
  6. php artisan migrate (throws error)

file: XXXXXX_create_test_table.php

id(); $table->dropPrimary(); }); } /** * Reverse the migrations. * * @return void */ public function down() { } };

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions