我正在使用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; }
}
}