2016-08-12 10 views
2

データベースからビューにデータを表示したいのですが、奇妙な問題が発生します。既に存在するためdatabase.mdfファイルを作成できません

エラー:

Cannot create file '~\MyProject\MyProject\App_Data\BlogContext.mdf' because it already exists. Change the file path or the file name, and retry the operation. CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

ビュー(CSHTML):

@foreach (var item in Model) 
{ 
    <tr> 
     <td> 
      @Html.DisplayFor(modelItem => item.Title) 
     </td> 
    </tr> 
} 

コントローラーのActionResultポスト:

public ActionResult Post() 
     { 
      return View(db.Posts.ToList()); 
     } 

ポストモデル:

public class Post 
{ 
    public virtual int Id { get; set; } 
    public virtual string Title { get; set; } 
    public virtual string Content { get; set; } 
    public virtual string ShortContent { get; set; } 
    public virtual string Meta { get; set; } 
    public virtual string UrlSlug { get; set; } 
    public virtual bool Published { get; set; } 
    public virtual DateTime? ModifiedDate { get; set; } 
    public virtual DateTime AddDate { get; set; } 

    public virtual PostCategory PostCategory { get; set; } 
    public virtual List<string> Tags { get; set; } 

}

私はビジュアルをやりたいとは思っていません。私は既にその方法と呼ばれるdbを持っているからですが、私は新しいものを作りたくありません。私はちょうどこれを使いたい。

どうすればよいですか?

+0

解決方法を見つけられましたか? – Unbreakable

+0

はい。 dbを更新して移行を追加すると、すべてがうまくいくようになりました。 – MadMike6661

答えて

1

私が使用:

update-database 

add-migration 
をこの問題を解決するためのコマンド

関連する問題