0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Symfony4.4で開発してきたプロジェクトをSymfny5.2に上げた(2021/03現在)

Last updated at Posted at 2021-03-15

ちなみにPHPバージョンは7.2

TL;DR

config/packages/doctrine_migrations.yaml更新

doctrine_migrations:
-    dir_name: '%kernel.project_dir%/src/Migrations'
-    namespace: App\Migrations
+    migrations_paths:
+        'App\Migrations': '%kernel.project_dir%/src/Migrations'
+    storage:
+        table_storage:
+            table_name: migration_versions    

※ 既存migrationがある場合はAbstractMigrationのnamespace更新

doctrine系更新

composer update doctrine/*
composer require doctrine/doctrine-bundle:^2.2 doctrine/doctrine-migrations-bundle:^3.0 doctrine/migrations:^3.1

doctrine以外のサードパーティの更新

それぞれSymfony5に対応しているバージョンを調べてcomposer require

Symfony自体の更新

  • composer.jsonのsymfony/から始まるパッケージのバージョンを ^4.4→^5.2に書き換える
  • composer.jsonのextra.symfony.requireを 4.4.*5.2.* に書き換える
composer update symfony/*

実際にやったことログ

いきなりSymfonyだけ上げようとする

  • composer.jsonのsymfony/から始まるパッケージのバージョンを ^4.4→^5.2に書き換える
  • composer.jsonのextra.symfony.requireを 4.4.*5.2.* に書き換える
composer update symfony/* -W

Problem 1
    - doctrine/doctrine-bundle[1.8.0, ..., 1.8.1] require symfony/framework-bundle ~2.7|~3.0|~4.0 -> found symfony/framework-bundle[v2.7.0-BETA1, ..., v2.8.52, v3.0.0-BETA1, ..., v3.4.47, v4.0.0-BETA1, ..., v4.4.20] but it conflicts with your root composer.json require (^5.2).
    - doctrine/doctrine-bundle[1.9.0, ..., 1.10.3] require symfony/framework-bundle ^2.7.22|~3.0|~4.0 -> found symfony/framework-bundle[v2.7.22, ..., v2.8.52, v3.0.0-BETA1, ..., v3.4.47, v4.0.0-BETA1, ..., v4.4.20] but it conflicts with your root composer.json require (^5.2).
    - doctrine/doctrine-bundle[1.11.0, ..., 1.11.2] require symfony/framework-bundle ^3.4|^4.1 -> found symfony/framework-bundle[v3.4.0-BETA1, ..., v3.4.47, v4.1.0-BETA1, ..., v4.4.20] but it conflicts with your root composer.json require (^5.2).
    - doctrine/doctrine-bundle[1.12.0-Beta1, ..., 1.12.0] require symfony/config ^3.4.30|^4.3.3 -> found symfony/config[v3.4.30, ..., v3.4.47, v4.3.3, ..., v4.4.20] but these were not loaded, likely because it conflicts with another require.
    - doctrine/doctrine-bundle[1.12.1, ..., 1.12.13] require symfony/cache ^3.4.30|^4.3.3 -> found symfony/cache[v3.4.30, ..., v3.4.47, v4.3.3, ..., v4.4.20] but these were not loaded, likely because it conflicts with another require.
    - Root composer.json requires doctrine/doctrine-bundle ^1.8 -> satisfiable by doctrine/doctrine-bundle[1.8.0, ..., 1.12.13].

要するにdoctrine/doctrine-bundleがSymfony4までしか許してないよ!というエラー

まずdoctrine/doctrine-bundleを更新する

doctrine/doctrine-bundle 1.x系ではSymfony4系しか対応してなくて、doctrine/doctrine-bundle 2.x系の今日時点の最新は2.2.3だった
https://github.com/doctrine/DoctrineBundle/releases/tag/2.2.3

doctrine/doctrine-bundleに依存しているパッケージでもアップデートが必要そうなのでバージョンを調べる。
doctrine/migrations-bundleは 3.0系で良さそうhttps://github.com/doctrine/DoctrineMigrationsBundle/blob/3.0.x/composer.json

必然的にdoctrine/migrationsも3.x系に上げる必要が出てくる

composer require doctrine/doctrine-bundle:^2.2 doctrine/doctrine-migrations-bundle:^3.0 doctrine/migrations:^3.1

composerのパッケージsync&install自体はうまくいくがキャッシュクリアがエラー

Executing script cache:clear [KO]
 [KO]
Script cache:clear returned with error code 1
!!  
!!  In ArrayNode.php line 327:
!!                                                                                 
!!    Unrecognized options "dir_name, namespace" under "doctrine_migrations". Ava  
!!    ilable options are "all_or_nothing", "check_database_platform", "connection  
!!    ", "custom_template", "em", "factories", "migrations", "migrations_paths",   
!!    "organize_migrations", "services", "storage".                                
!!                                                                                 
!!  

config/packages/doctrine_migrations.yamlの設定が正しくないというエラー。次のように変更する。

doctrine_migrations:
-    dir_name: '%kernel.project_dir%/src/Migrations'
-    namespace: App\Migrations
+    migrations_paths:
+        'App\Migrations': '%kernel.project_dir%/src/Migrations'
composer require doctrine/doctrine-bundle:^2.2 doctrine/doctrine-migrations-bundle:^3.0 doctrine/migrations:^3.1

今度はキャッシュクリアまで通った。

doctrine/migrations 3ではAbstractMigrationクラスのnamespaceが変わっているので、既存のmigrationにも反映しておく。

- use Doctrine\DBAL\Migrations\AbstractMigration;
+ use Doctrine\Migrations\AbstractMigration;

up(), down()メソッドに :void も必要になったので追加する。

migrationバージョンテーブル名のデフォルト名が変わった対応

Doctrineマイグレーションの「どこまで適用済か」を保存するテーブルのデフォルト名が migration_versions だった時代に作り始めたプロジェクトであれば、 doctrine_migration_versions という新しいバージョンテーブルが空っぽ扱いされてマイグレーションを最初から実行しようとしてしまいます。

Base table or view already exists: 1050 Table... のようなエラーが出たらコレです。

以前から使っているバージョンテーブルを今後も使うためにバージョンテーブル名を指定することで回避できます。

doctrine_migrations:
+    storage:
+        table_storage:
+            table_name: migration_versions
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?