2

I want to ask how to fix this error in laravel heroku hosting in my local I was using mysql but in heroku I switched to postgres and I get those errors while migrating.

In Connection.php line 678:

SQLSTATE[42704]: Undefined object: 7 ERROR: data type json has no default operator class for access method "btree"
HINT: You must specify an operator class for the index or define a default operator class for the data type. (SQL: alter table "functions" add constraint "functions_function_elements_unique" unique ("function_elements"))

In Connection.php line 471:

SQLSTATE[42704]: Undefined object: 7 ERROR: data type json has no default operator class for access method "btree"
HINT: You must specify an operator class for the index or define a default operator class for the data type.

3
  • did you set the specify postegree instate of Mysql Commented Mar 27, 2021 at 21:59
  • yeah i did in heroku this is why i think there is no reasen to do it in my local while i m using mysql can this be the reasen of the eroor Commented Mar 27, 2021 at 22:07
  • What good is a B-tree index on a JSON attribute?? Commented Mar 28, 2021 at 5:08

2 Answers 2

0

By default Laravel ships with MySQL. You may want to try out other SQL database type, changing that is very simple however there are some small configurations you have to make if your database of choice is postgres.

  1. Installation Download PostgreSQL to your pc from https://www.postgresql.org/download/ Or directly here (for windows) https://get.enterprisedb.com/postgresql/postgresql-12.1-3-windows-x64.exe Then Install.
  2. php.ini MySQL is the default therefore there’s need to activate PostgreSQL for use with PHP on your pc by editing the php.ini Search for these two lines within your php.ini and remove the “;” in front of each:

;extension=pdo_pgsql ;extension=pgsql

to (notice that “;” was removed)

extension=pdo_pgsql extension=pgsql

  1. .env Change the following as appropriate within the Laravel’s .env file (all the defaults are ok except DB_DATABASE and DB_PASSWORD that you may have to change):
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=database_name
DB_USERNAME=postgres
DB_PASSWORD=your_choosen_password
Sign up to request clarification or add additional context in comments.

Comments

0

hello guys so i found the solution here :) ;

`
Schema::create('fdeg_functions', function (Blueprint $table) {
        $table->id();
        $table->timestamps();
        $table->Json("function_elements")->unique();
    });`

So , All what I shall do is to convert json to string and it worked too good ; and i think this will not have any bad effects to the application , tell me what you see , and i hope this will help other people :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.