我收到来自Media Library包的根错误。
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'generated_conversions' in 'field list' (SQL: insert into `media` (...经过研究,我发现6天前有一个从v8到v9的升级,要求在介质表中添加一个JSON列generated_conversions。
下面是建议的迁移文件
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
class AddGeneratedConversionsToMediaTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up() {
if ( ! Schema::hasColumn( 'media', 'generated_conversions' ) ) {
Schema::table( 'media', function ( Blueprint $table ) {
$table->json( 'generated_conversions' );
});
}
Media::query()
->whereNull('generated_conversions')
->orWhere('generated_conversions', '')
->orWhereRaw("JSON_TYPE(generated_conversions) = 'NULL'")
->update([
'generated_conversions' => DB::raw('custom_properties->"$.generated_conversions"'),
// OPTIONAL: Remove the generated conversions from the custom_properties field as well:
// 'custom_properties' => DB::raw("JSON_REMOVE(custom_properties, '$.generated_conversions')")
]);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down() {
/* Restore the 'generated_conversions' field in the 'custom_properties' column if you removed them in this migration
Media::query()
->whereRaw("JSON_TYPE(generated_conversions) != 'NULL'")
->update([
'custom_properties' => DB::raw("JSON_SET(custom_properties, '$.generated_conversions', generated_conversions)")
]);
*/
Schema::table( 'media', function ( Blueprint $table ) {
$table->dropColumn( 'generated_conversions' );
});
}
}但是当我运行php artisan migrate:fresh --seed时,我得到了一个错误
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_conversion' at line 1 (SQL: update `media` set `generated_conversions` = custom_properties->"$.generated_conversions", `media`.`updated_at` = 2021-04-17 20:22:02 where `generated_conversions` is null or `generated_conversions` = or JSON_TYPE(generated_conversions) = 'NULL')有人知道这个文件的问题吗?谢谢
发布于 2021-10-10 15:51:10
您需要遵循https://github.com/spatie/laravel-medialibrary/blob/main/UPGRADING.md提供的升级指南
## From v8 to v9
- add a `json` column `generated_conversions` to the `media` table (take a look at the default migration for the exact definition). You should copy the values you now have in the `generated_conversions` key of the `custom_properties` column to `generated_conversions`
- You can create this migration by running `php artisan make:migration AddGeneratedConversionsToMediaTable`.
- Here is the content that should be in the migration file
```php使用Migrations\Database\Migrations\Migration;
使用Illuminate\Database\Schema\Blueprint;
使用Illuminate\Support\Facades\DB;
使用Illuminate\Support\Facades\Schema;
使用Spatie\MediaLibrary\MediaCollections\Models\Media;
类AddGeneratedConversionsToMediaTable扩展了迁移{
/** * Run the migrations.
*
* @return void
*/
public function up() {
if ( ! Schema::hasColumn( 'media', 'generated_conversions' ) ) {
Schema::table( 'media', function ( Blueprint $table ) {
$table->json( 'generated_conversions' );
} );
} Media::query() ->where(function ($query) { $query->whereNull('generated_conversions') ->orWhere('generated_conversions', '') ->orWhereRaw("JSON_TYPE(generated_conversions) = 'NULL'"); }) ->whereRaw("JSON_LENGTH(custom_properties) > 0") ->update([ 'generated_conversions' => DB::raw('custom_properties->"$.generated_conversions"'), // OPTIONAL: Remove the generated conversions from the custom_properties field as well: // 'custom_properties' => DB::raw("JSON_REMOVE(custom_properties, '$.generated_conversions')") ]);}/** * Reverse the migrations.
*
* @return void
*/
public function down() {
/* Restore the 'generated_conversions' field in the 'custom_properties' column if you removed them in this migration
Media::query()
->whereRaw("JSON_TYPE(generated_conversions) != 'NULL'")
->update([
'custom_properties' => DB::raw("JSON_SET(custom_properties, '$.generated_conversions', generated_conversions)")
]);
*/ Schema::table( 'media', function ( Blueprint $table ) { $table->dropColumn( 'generated_conversions' ); } );}}
- rename `conversion_file_namer` key in the `media-library` config to `file_namer`. This will support both the conversions and responsive images from now on. More info [in our docs](https://spatie.be/docs/laravel-medialibrary/v9/advanced-usage/naming-generated-files).
- You will also need to change the value of this configuration key as the previous class was removed, the new default value is `Spatie\MediaLibrary\Support\FileNamer\DefaultFileNamer::class`
- in several releases of v8 config options were added. We recommend going over your config file in `config/media-library.php` and add any options that are present in the default config file that ships with this package.
```javascripthttps://stackoverflow.com/questions/67142630
复制相似问题