Reputation: 268
I want to display data in view from my database but some strange problem is appears.
Error:
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.
View(cshtml):
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
</tr>
}
Controller ActionResult Post:
public ActionResult Post()
{
return View(db.Posts.ToList());
}
Post Model:
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; }
}
I don't what Visual want to do, because It's true i already have a db called that way, but i dont want to make a new. I just want to use this one.
What to do?
Upvotes: 3
Views: 5032
Reputation: 268
I used:
update-database
and
add-migration
commands to fix this problem.
Upvotes: 1