LoginSignup
2
1

More than 5 years have passed since last update.

.NET Core プロジェクトで「'Update-Database' is not recognized」が出るときの対処

Posted at

.NET Core プロジェクトでデータベースを更新するために Package Manager Console を開いて Update-Database を実行することはたぶん一般的(?)だと思うのですが、(たぶんこれは僕の開発環境固有の問題っぽいのですが)ある時からこれが実行できなくなってしまいました。

ちなみに環境情報を記しておくと Windows 10 Home, Visual Studio Community 2017 Version 15.3.0, .NET Core SDK 2.0 です。

'Update-Database' is not recognized

Update-Database がこんな具合に実行できません。

PM> Update-Database
Update-Database : The term 'Update-Database' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, 
verify that the path is correct and try again.
At line:1 char:1
+ Update-Database
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Update-Database:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

(暫定)対処

試行錯誤した結果見つけた暫定対処としては、Package Manager Console でのカレントディレクトリをプロジェクトディレクトリに手動で設定してあげると良いみたいです(しかしこれ毎回やるのは明らかに間違っている気がするのであくまでも暫定対処です)。

PM> pwd
C:\Projects\WebApplication1   ← これはソリューションのディレクトリなので

PM> cd WebApplication1   ← さらにプロジェクトのディレクトリに進んでから
PM> Update-Database   ← 目的のコマンドを実行する

他環境での挙動

Package Manager Console でのカレントディレクトリが必ずプロジェクトディレクトリになっていないと Update-Database が実行できないか、というと、他の環境(クリーンに構築してみた環境)ではカレントディレクトリがソリューションディレクトリの状態でも Update-Database は実行できていたりしました。

ちょっと問題の原因が特定できかねていますが、暫定の対処をメモとして残しておきます。

2
1
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
2
1