guillaumebriday / laravel-blog

Laravel 10.0 blog application with Hotwire, Horizon, Telescope, Sanctum, Breeze and Pusher
MIT License
1.72k stars 559 forks source link

Cant run artisan migrate --seed [BUG] #126

Closed jameswong3388 closed 2 years ago

jameswong3388 commented 2 years ago

Please read the README before considering opening an issue and be sure to check that the bug is not related to your development environment.

Describe the bug

I Have come to the last step of the installation where you need to migrate the databases and seed all the data, but this popped out of nowhere.

PS C:\Users\User\PhpstormProjects\laravel-blog> php .\artisan migrate --seed
Migrating: 2022_04_30_011124_add_generated_conversions_to_media_table

   Illuminate\Database\QueryException 

  SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '>"$.generated_conversions", `media`.`updated_at` = ? where (`generated_conver...' at line 1 (SQL: update `media` set `generated_conversions` = custom_properties->"$.generated_conversions", `media`.`updated_at` = 2022-04-30 09:50:03 where (`generated_conversions` is null or `generated_conversions` =  or JSON_TYPE(generated_conversions) = 'NULL') and JSON_LENGTH(custom_properties) > 0)

  at C:\Users\User\PhpstormProjects\laravel-blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:742
    738▕         // If an exception occurs when attempting to run a query, we'll format the error
    739▕         // message to include the bindings with SQL, which will make this exception a
    740▕         // lot more helpful to the developer instead of just the database's errors.
    741▕         catch (Exception $e) {
  ➜ 742▕             throw new QueryException(
    743▕                 $query, $this->prepareBindings($bindings), $e
    744▕             );
    745▕         }
    746▕     }

  1   C:\Users\User\PhpstormProjects\laravel-blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:548
      PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '>"$.generated_conversions", `media`.`updated_at` = ? where (`generated_conver...' at line 1")

  2   C:\Users\User\PhpstormProjects\laravel-blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:548
      PDO::prepare("update `media` set `generated_conversions` = custom_properties->"$.generated_conversions", `media`.`updated_at` = ? where (`generated_conversions` is null or `generated_conversions` = ? or JSON_TYPE(generated_conversions) = 'NULL') and JSON_LENGTH(custom_properties) > 0")

Environment

I am developing on local PC with xampp handling the PHP and Mysql PHP - 8.1.5 MariaDB - 10.4.24

Screenshots

image

guillaumebriday commented 2 years ago

It sounds like to be related to mariadb. I guess it cannot execute the latest migration.

Please install the project as described in the README if you want to be sure to don't have any issue 👍

jameswong3388 commented 2 years ago

@guillaumebriday, i solved the issue by installing MySQL, instead of using xampp

ricoxor commented 1 year ago

For MariaDB users, line 32 replace :

'generated_conversions' => DB::raw('custom_properties->"$.generated_conversions"'),

by

'generated_conversions' => DB::raw('JSON_EXTRACT(custom_properties, "$.generated_conversions")'),

Worked for me !