MVC 上的 InvalidOperationException
InvalidOperationException on MVC
我正在与其他学生一起使用 Team Foundation Server 在线作为源代码进行项目,我们的客户是 Visual Studio.
每当我浏览我的应用程序或单击与我的数据库实体相关的任何内容时,我是唯一遇到以下异常错误的人:
"An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code."
我尝试更新数据库,但我也收到此错误:
"There is already an object named 'Post' in the database."
我也做了 Add-migration "name of new migration",但我一直收到这个:
"Unable to generate an explicit migration because the following explicit migrations are pending: [201502020217243_InitialCreate]. Apply the pending explicit migrations before attempting to generate a new explicit migration."
The code for the InitialCreate.cs:
namespace Aliens.Migrations
{
using System;
using System.Data.Entity.Migrations;
public partial class InitialCreate : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.Post",
c => new
{
PostID = c.Int(nullable: false, identity: true),
Alias = c.String(),
Location = c.String(),
PostDate = c.DateTime(nullable: false),
PostTitle = c.String(),
PostMessage = c.String(),
})
.PrimaryKey(t => t.PostID);
CreateTable(
"dbo.Profile",
c => new
{
ProfileID = c.Int(nullable: false, identity: true),
FirstName = c.String(),
LastName = c.String(),
ProfileAlais = c.String(),
})
.PrimaryKey(t => t.ProfileID);
AddColumn("dbo.Alien", "Post", c => c.String());
}
public override void Down()
{
DropColumn("dbo.Alien", "Post");
DropTable("dbo.Profile");
DropTable("dbo.Post");
}
}
}
Configuration.cs 的代码是:
namespace Aliens.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
internal sealed class Configuration : DbMigrationsConfiguration<Aliens.DAL.AlienContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
ContextKey = "Aliens.DAL.AlienContext";
}
}
}
我创建了一个空的 Up() 方法,注释掉了真正的 InitialCreat.cs,运行 它,现在我可以创建下一个迁移了。
我终于按照上面描述的对每个待定迁移所做的操作解决了这个问题。然后我使用这个可爱的命令 Add-Migration Initial -IgnoreChanges
我正在与其他学生一起使用 Team Foundation Server 在线作为源代码进行项目,我们的客户是 Visual Studio.
每当我浏览我的应用程序或单击与我的数据库实体相关的任何内容时,我是唯一遇到以下异常错误的人:
"An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code."
我尝试更新数据库,但我也收到此错误:
"There is already an object named 'Post' in the database."
我也做了 Add-migration "name of new migration",但我一直收到这个:
"Unable to generate an explicit migration because the following explicit migrations are pending: [201502020217243_InitialCreate]. Apply the pending explicit migrations before attempting to generate a new explicit migration." The code for the InitialCreate.cs:
namespace Aliens.Migrations
{
using System;
using System.Data.Entity.Migrations;
public partial class InitialCreate : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.Post",
c => new
{
PostID = c.Int(nullable: false, identity: true),
Alias = c.String(),
Location = c.String(),
PostDate = c.DateTime(nullable: false),
PostTitle = c.String(),
PostMessage = c.String(),
})
.PrimaryKey(t => t.PostID);
CreateTable(
"dbo.Profile",
c => new
{
ProfileID = c.Int(nullable: false, identity: true),
FirstName = c.String(),
LastName = c.String(),
ProfileAlais = c.String(),
})
.PrimaryKey(t => t.ProfileID);
AddColumn("dbo.Alien", "Post", c => c.String());
}
public override void Down()
{
DropColumn("dbo.Alien", "Post");
DropTable("dbo.Profile");
DropTable("dbo.Post");
}
}
}
Configuration.cs 的代码是:
namespace Aliens.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
internal sealed class Configuration : DbMigrationsConfiguration<Aliens.DAL.AlienContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
ContextKey = "Aliens.DAL.AlienContext";
}
}
}
我创建了一个空的 Up() 方法,注释掉了真正的 InitialCreat.cs,运行 它,现在我可以创建下一个迁移了。
我终于按照上面描述的对每个待定迁移所做的操作解决了这个问题。然后我使用这个可爱的命令 Add-Migration Initial -IgnoreChanges