【发布时间】:2013-07-29 04:17:07
【问题描述】:
我正在开发一个在 Visual Studio 2012 中使用 MVC4 的项目,并在表格中添加了一列。
现在当我想调试我的项目时,错误提示使用迁移来更新我的数据库。
我必须做什么?
我搜索了很多,发现了一些方法,例如:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer<ResTabelaIndex>(null);
}
但不知道如何以及在哪里实现这个...在app_start、global.asax 等中尝试过...
我发现,直接在控制台中从 nuget 启用迁移。
但我做不到。
我使用的命令:
Enable-Migrations -EnableAutomaticMigrations
==> 控制台说找到了多个上下文。
要启用使用,Enable-Migrations -ContextTypeName NameOfTheNamespace.Models.DefaultConnection
但是不知道-ContextTypeName是什么,试了很多还是看不懂。
My Model Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.Entity.Migrations;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.Infrastructure;
namespace Vista.Models
{
public class TabelaIndex
{
public int ID { get; set; }
public string n_empresa { get; set; }
public string titulo{ get; set; }
public string url { get; set; }
public string imagens { get; set; }
}
public class DefaultConnection : DbContext
{
public DbSet<TabelaIndex> ResTabelaIndex { get; set; }
}
}
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-mvc-4 migration