LoginSignup
0
1

More than 1 year has passed since last update.

EntityFramework Core でDB構築をしようとして詰まった時の話(記録用)

Posted at

作業をして詰まったのでその記録用に残します。

開発環境

  • OS:Windows10
  • ASP.NET
  • DB:PostgreSQL

作業

まだASP.NETは不慣れなのですが、開発で使用するために環境構築を行っていました。

パッケージマネージャーコンソールでコマンドを実行すると下記のエラーが出てしまいました。

Update-Database
Build started...
Build succeeded.
No DbContext was found in assembly 'プロジェクト名'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.

調べたところどうやらDBContext を定義していないプロジェクトでマイグレーションコマンドを実行しようとすると起きる事象のようです。

 対処

もう一度同じコマンド'Update-Database'を打ったところ(ダメ元)下記が返ってきました。

互換性がないので指定されたフレームワークをインストールしてみてね。とのことでしたので、リンクから.NET Core 2.0 Runtime (v2.0.9) をインストールしました。

Update-Database
Build started...
Build succeeded.

It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '2.0.0' was not found.
  - The following frameworks were found:
      3.1.21 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      5.0.12 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.0.0&arch=x64&rid=win10-x64

再度'Update-Database'コマンドを実行。
すると下記が返ってきました。

Your startup project 'Infrastructure' doesn't reference Microsoft.EntityFrameworkCore.Design. This

エラーの通りMicrosoft.EntityFrameworkCore.Design.をインストールしました。

ソリューションエクスプローラー → プロジェクト名を右クリック→ NuGetパッケージの管理からインストール実行

Build started...
Build succeeded.
Microsoft.EntityFrameworkCore.Model.Validation[10400]
      Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data; this mode should only be enabled during development.

やっと構築できました。

succeededと出ているのになぜDBに接続できないのだろう?と不思議だったのですが、成功していなかったんですね。

参考サイト

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