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 1 year has passed since last update.

php artisan make:migration create_blogs_table 実行時にPHPのバージョン違いによるエラーが発生する

Last updated at Posted at 2021-11-07

#目次
概要
実施環境
問題発生まで
問題
結論
解決するまでにやったこと

#概要
https://www.youtube.com/watch?v=plDBsStXuO4&list=PLCyDm9NTxdhLnA4tH5ToQR1K1LcWIAdOa&index=3

こちらの動画を参考にしてLaravelアプリを作成する過程で以下のエラーが発生したので解決するまでにしたことを記しました。

#実施環境
#####ハードウェア環境

項目 情報
OS MacOS Big Sur (11.5.2)
ハードウェア MacBook Pro (Retina, 13-inch, Late 2013)
プロセッサ 2.4 GHz デュアルコアIntel Core i5
メモリ 4 GB 1600 MHz DDR3
#####ソフトウェア環境
項目 備考
:-: :-:
MAMP (v6.6) 無料版
Laravel (v8.6.5)
Composer (v2.1.9) homebrewでインストール

#問題発生まで

こちらの動画及び

こちらの動画の6:30までと同じことを行いました。
MAMPやLaravel、Composerは、私が使用しているものと動画で使用されているものとでバージョン差があります。

#問題

#02の動画の6:30にあるように下記のコマンドを実行してマイグレーションファイルを作成しようとしたところ

$ php artisan make:migration create_blogs_table

下記のエラーが発生しました。

Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0". You are running 7.3.24-(to be removed in future macOS). in /Applications/MAMP/htdocs/blog/vendor/composer/platform_check.php on line 24

#結論
下記のコマンドを実行するとうまくいきました

$ composer update
$ composer install --ignore-platform-reqs 

Composerが最新になっていなかったため、PHPのバージョンチェックを無視するコマンドが機能していなかったと思われます

#解決するまでにやったこと 
※長いです

####1.composer install --ignore-platform-reqs を実行

composer install --ignore-platform-reqs

実行結果

Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
78 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

####2.再度 php artisan make:migration create_blogs_table を実行するも結果は変わらず

Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0". You are running 7.3.24-(to be removed in future macOS). in /Applications/MAMP/htdocs/blog/vendor/composer/platform_check.php on line 24

####3.composer dump-autoload を実行

$ composer dump-autoload      

結果

Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
Generated optimized autoload files containing 4974 classes

####4.再度 php artisan make:migration create_blogs_table を実行するも結果は変わらず

####5.composer config platform.php 7.3.24 を実行

$ composer config platform.php 7.3.24

実行結果は出ませんでした

####6.再度 php artisan make:migration create_blogs_table を実行するも結果は変わらず

####7.再度 composer dump-autoload を実行
結果変わらず

Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
Generated optimized autoload files containing 4974 classes

####8.再度 php artisan make:migration create_blogs_table を実行するも結果は変わらず

####9.再度 composer install --ignore-platform-reqs を実行

結果
さきほどの(1.composer install --ignore-platform-reqs を実行)のときにはなかった警告文が出ました

Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.

Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update` or `composer update <package name>`.
//↑先ほどは無かった警告文

Nothing to install, update or remove
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
78 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

####10.言われた通りにcomposer update を実行

$ composer update

結果

Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 9 updates, 4 removals
  - Removing dflydev/dot-access-data (v3.0.1)
  - Removing league/config (v1.1.1)
  - Removing nette/schema (v1.2.2)
  - Removing nette/utils (v3.2.5)
  - Downgrading league/commonmark (2.0.2 => 1.6.6)
  - Upgrading phpunit/php-code-coverage (9.2.7 => 9.2.8)
  - Downgrading psr/log (2.0.0 => 1.1.4)
  - Upgrading symfony/console (v5.3.7 => v5.3.10)
  - Upgrading symfony/http-foundation (v5.3.7 => v5.3.10)
  - Upgrading symfony/http-kernel (v5.3.9 => v5.3.10)
  - Upgrading symfony/string (v5.3.7 => v5.3.10)
  - Upgrading symfony/translation (v5.3.9 => v5.3.10)
  - Upgrading symfony/var-dumper (v5.3.8 => v5.3.10)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 9 updates, 4 removals
  - Downloading symfony/var-dumper (v5.3.10)
  - Downloading symfony/string (v5.3.10)
  - Downloading symfony/console (v5.3.10)
  - Downloading psr/log (1.1.4)
  - Downloading symfony/http-foundation (v5.3.10)
  - Downloading symfony/http-kernel (v5.3.10)
  - Downloading symfony/translation (v5.3.10)
  - Downloading league/commonmark (1.6.6)
  - Downloading phpunit/php-code-coverage (9.2.8)
  - Removing nette/utils (v3.2.5)
  - Removing nette/schema (v1.2.2)
  - Removing league/config (v1.1.1)
  - Removing dflydev/dot-access-data (v3.0.1)
  - Upgrading symfony/var-dumper (v5.3.8 => v5.3.10): Extracting archive
  - Upgrading symfony/string (v5.3.7 => v5.3.10): Extracting archive
  - Upgrading symfony/console (v5.3.7 => v5.3.10): Extracting archive
  - Downgrading psr/log (2.0.0 => 1.1.4): Extracting archive
  - Upgrading symfony/http-foundation (v5.3.7 => v5.3.10): Extracting archive
  - Upgrading symfony/http-kernel (v5.3.9 => v5.3.10): Extracting archive
  - Upgrading symfony/translation (v5.3.9 => v5.3.10): Extracting archive
  - Downgrading league/commonmark (2.0.2 => 1.6.6): Extracting archive
  - Upgrading phpunit/php-code-coverage (9.2.7 => 9.2.8): Extracting archive
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
77 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi
No publishable resources for tag [laravel-assets].
Publishing complete.

####11.再度 composer install --ignore-platform-reqs を実行
結果

Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
77 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

####12.再度 php artisan make:migration create_blogs_table を実行

結果:うまくいきました

Created Migration: 2021_10_30_192345_create_blogs_table
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?