- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
在进行 EF5 代码迁移时遇到了一个反复出现的奇怪问题,现在让我无法工作。尝试运行 update-database
并收到此错误:
There is already an object named 'RequestStatus' in the database.
详细的日志转储:
PM> update-database -v
Using StartUp project 'LicensingWorkflow'.
Using NuGet project 'LicensingWorkflow'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'LicensingWorkflow.Models.LicenseWorkflowContext' (DataSource: (localdb)\v11.0, Provider: System.Data.SqlClient, Origin: Convention).
Applying code-based migrations: [201311111934210_AddRequestStatusToContext].
Applying code-based migration: 201311111934210_AddRequestStatusToContext.
CREATE TABLE [dbo].[RequestStatus] (
[Id] [bigint] NOT NULL IDENTITY,
[Status] [nvarchar](max),
CONSTRAINT [PK_dbo.RequestStatus] PRIMARY KEY ([Id])
)
System.Data.SqlClient.SqlException (0x80131904): There is already an object named 'RequestStatus' in the database.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at System.Data.Entity.Migrations.DbMigrator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement)
at System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable`1 migrationStatements)
at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable`1 operations, Boolean downgrading, Boolean auto)
at System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
ClientConnectionId:38d030fa-496e-4091-88eb-49093d76da14
There is already an object named 'RequestStatus' in the database.
我已经尝试了在 Google 上找到的一切。我尝试过但没有提供任何结果的事情:
最让人恼火的是我的同事在同一个代码库中,根本没有遇到这个问题。我正在使用 VS2012 和 EF5 的 LocalDb。
一些引用代码
数据库初始化器
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<LicenseWorkflowContext>());
数据库上下文
namespace LicensingWorkflow.Models {
public class LicenseWorkflowContext : DbContext {
public DbSet<License> Licenses { get; set; }
public DbSet<RequestHistory> RequestHistories { get; set; }
public DbSet<RequestType> RequestTypes { get; set; }
public DbSet<HistoryStatus> HistoryStatuses { get; set; }
public DbSet<Request> Requests { get; set; }
public DbSet<LicenseStatus> LicenseStatuses { get; set; }
public DbSet<RequestEntryAnswerReference> RequestEntryAnswerReferences { get; set; }
public DbSet<Comment> Comments { get; set; }
public DbSet<SuretyBond> SuretyBonds { get; set; }
public DbSet<RequestStatus> RequestStatuses { get; set; }
}
}
失败的 RequestStatus。
namespace LicensingWorkflow.Models {
public class RequestStatus {
public long Id { get; set; }
public string Status { get; set; }
}
}
它是请求模型的一部分
namespace LicensingWorkflow.Models {
public class Request {
public long Id { get; set; }
public string RequesterId { get; set; }
public string SupervisorId { get; set; }
public DateTime RequestDate { get; set; }
public long SurveyId { get; set; }
public string WorkerId { get; set; }
public long RequestTypeId { get; set; }
public string State { get; set; }
public List<Comment> Comments { get; set; }
public RequestEntryAnswerReference ReqeustEntryAnswerReference { get; set; }
public long? LicenseId { get; set; }
public RequestStatus RequestStatus { get; set; }
}
}
种子方法/Configuration.cs
public sealed class Configuration : DbMigrationsConfiguration<LicensingWorkflow.Models.LicenseWorkflowContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
}
protected override void Seed(LicensingWorkflow.Models.LicenseWorkflowContext context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data. E.g.
//
// context.People.AddOrUpdate(
// p => p.FullName,
// new Person { FullName = "Andrew Peters" },
// new Person { FullName = "Brice Lambson" },
// new Person { FullName = "Rowan Miller" }
// );license branch renewal deficiency surrender
//
var status1 = new LicenseStatus { Id = 1, Status = "ok" };
var status2 = new LicenseStatus { Id = 2, Status = "deficient" };
var status3 = new LicenseStatus{Id = 3, Status = "inactive"};
context.LicenseStatuses.AddOrUpdate(
ls => ls.Id,
status1,
status2,
status3
);
var license = new License {
Id = 1,
LicenseStatus = new LicenseStatus {Status = "ok"},
LicenseNumber = 12345,
OwnerId = "022567",
ObtainedDate = new DateTime(2012, 10, 3),
ExpirationDate = new DateTime(2013, 12, 12),
State = "Minnesota",
Type = "individual"
};
var license2 = new License {
Id = 2,
LicenseStatus = new LicenseStatus {Status = "deficient"},
LicenseNumber = 12346,
OwnerId = "022567",
ObtainedDate = new DateTime(2012, 10, 3),
ExpirationDate = new DateTime(2013, 12, 12),
State = "Texas",
Type = "individual"
};
var license3 = new License {
Id = 3,
LicenseStatus = new LicenseStatus { Status = "ok" },
LicenseNumber = 12347,
OwnerId = "025253",
ObtainedDate = new DateTime(2012, 10, 3),
ExpirationDate = new DateTime(2013, 12, 12),
State = "Minnesota",
Type = "individual"
};
var license4 = new License {
Id = 4,
LicenseStatus = new LicenseStatus { Status = "deficient" },
LicenseNumber = 12348,
OwnerId = "025253",
ObtainedDate = new DateTime(2012, 10, 3),
ExpirationDate = new DateTime(2013, 12, 12),
State = "Texas",
Type = "individual"
};
context.Licenses.AddOrUpdate(
l => l.Id,
license,
license2
);
context.RequestTypes.AddOrUpdate(
rt => rt.Id,
new RequestType { Id = 1, Type = "license" },
new RequestType { Id = 2, Type = "renewal" },
new RequestType { Id = 3, Type = "deficiency" },
new RequestType { Id = 4, Type = "surrender" },
new RequestType { Id = 5, Type = "branch" },
new RequestType { Id = 6, Type = "doNotRenew"}
);
var requestStatus1 = new RequestStatus() {
Id = 1,
Status = "submitted"
};
var requestStatus2 = new RequestStatus() {
Id = 2,
Status = "approved"
};
var requestStatus3 = new RequestStatus() {
Id = 3,
Status = "processing"
};
var requestStatus4 = new RequestStatus() {
Id = 4,
Status = "completed"
};
var requestStatus5 = new RequestStatus() {
Id = 5,
Status = "withdrawn"
};
var requestStatus6 = new RequestStatus() {
Id = 6,
Status = "denied"
};
context.RequestStatuses.AddOrUpdate(
rs => rs.Id,
requestStatus1,
requestStatus2,
requestStatus3,
requestStatus4,
requestStatus5,
requestStatus6
);
var request1 = new Request {
Id = 1,
RequesterId = "123",
RequestDate = DateTime.Now,
RequestTypeId = 1,
SupervisorId = "022567",
State = "California",
WorkerId = "",
SurveyId = 62
};
var unassignedRequest1 = new Request{
Id = 2,
RequesterId = "123",
RequestDate = DateTime.Now,
RequestTypeId = 1,
SupervisorId = "022567",
State = "NewMexico",
WorkerId = ""
};
var unassignedRequest2 = new Request {
Id = 3,
RequesterId = "123",
RequestDate = DateTime.Now,
RequestTypeId = 1,
SupervisorId = "123",
State = "Missouri",
WorkerId = ""
};
var unassignedRequest3 = new Request {
Id = 4,
RequesterId = "123",
RequestDate = DateTime.Now,
RequestTypeId = 1,
SupervisorId = "123",
State = "Florida",
WorkerId = ""
};
context.Requests.AddOrUpdate(
r => r.Id,
unassignedRequest1,
unassignedRequest2,
unassignedRequest3,
request1
);
var requestEntryAnswerReference = new RequestEntryAnswerReference {
Id = 1,
RequestId = 1,
ReferenceKey = "xxxxx-xxxxx-xxxxxx-xxxxx"
};
context.RequestEntryAnswerReferences.AddOrUpdate(
r => r.Id,
requestEntryAnswerReference
);
var comment1 = new Comment(){
Id = 1,
CommentText = "Test test test",
CommenterId = "123",
PostedDate = DateTime.Now,
RequestId = 1
};
var comment2 = new Comment() {
Id = 2,
CommentText = "Test test test",
CommenterId = "123",
PostedDate = DateTime.Now,
RequestId = 1
};
var comment3 = new Comment() {
Id = 3,
CommentText = "Test test test",
CommenterId = "123",
PostedDate = DateTime.Now,
RequestId = 1
};
context.Comments.AddOrUpdate(
r => r.Id,
comment1,
comment2,
comment3
);
request1.Comments = new List<Comment> {
comment1,
comment2,
comment3
};
context.Requests.AddOrUpdate(
r => r.Id,
request1
);
var hstatus1 = new HistoryStatus() { Id = 1, Status = "approved" };
var hstatus2 = new HistoryStatus() { Id = 2, Status = "denied" };
var hstatus3 = new HistoryStatus() { Id = 3, Status = "completed" };
var hstatus4 = new HistoryStatus() { Id = 4, Status = "withdrawl" };
var hstatus5 = new HistoryStatus() { Id = 5, Status = "assigned" };
var hstatus6 = new HistoryStatus() { Id = 6, Status = "unassigned" };
context.HistoryStatuses.AddOrUpdate(
hs => hs.Id,
hstatus1,
hstatus2,
hstatus3,
hstatus4,
hstatus5,
hstatus6
);
}
}
}
最佳答案
确保连接字符串的名称与您尝试更新的 DbContext 相同。换句话说,您正在尝试修改现有数据库。
关于c# - EF 5 代码迁移错误 : "There is already an object named _____ in the database",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19964679/
我已经使用 vue-cli 两个星期了,直到今天一切正常。我在本地建立这个项目。 https://drive.google.com/open?id=0BwGw1zyyKjW7S3RYWXRaX24tQ
您好,我正在尝试使用 python 库 pytesseract 从图像中提取文本。请找到代码: from PIL import Image from pytesseract import image_
我的错误 /usr/bin/ld: errno: TLS definition in /lib/libc.so.6 section .tbss mismatches non-TLS reference
我已经训练了一个模型,我正在尝试使用 predict函数但它返回以下错误。 Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]])
根据Microsoft DataConnectors的信息我想通过 this ODBC driver 创建一个从 PowerBi 到 PostgreSQL 的连接器使用直接查询。我重用了 Micros
我已经为 SoundManagement 创建了一个包,其中有一个扩展 MediaPlayer 的类。我希望全局控制这个变量。这是我的代码: package soundmanagement; impo
我在Heroku上部署了一个应用程序。我正在使用免费服务。 我经常收到以下错误消息。 PG::Error: ERROR: out of memory 如果刷新浏览器,就可以了。但是随后,它又随机发生
我正在运行 LAMP 服务器,这个 .htaccess 给我一个 500 错误。其作用是过滤关键字并重定向到相应的域名。 Options +FollowSymLinks RewriteEngine
我有两个驱动器 A 和 B。使用 python 脚本,我在“A”驱动器中创建一些文件,并运行 powerscript,该脚本以 1 秒的间隔将驱动器 A 中的所有文件复制到驱动器 B。 我在 powe
下面的函数一直返回这个错误信息。我认为可能是 double_precision 字段类型导致了这种情况,我尝试使用 CAST,但要么不是这样,要么我没有做对...帮助? 这是错误: ERROR: i
这个问题已经有答案了: Syntax error due to using a reserved word as a table or column name in MySQL (1 个回答) 已关闭
我的数据库有这个小问题。 我创建了一个表“articoli”,其中包含商品的品牌、型号和价格。 每篇文章都由一个 id (ID_ARTICOLO)` 定义,它是一个自动递增字段。 好吧,现在当我尝试插
我是新来的。我目前正在 DeVry 在线学习中级 C++ 编程。我们正在使用 C++ Primer Plus 这本书,到目前为止我一直做得很好。我的老师最近向我们扔了一个曲线球。我目前的任务是这样的:
这个问题在这里已经有了答案: What is an undefined reference/unresolved external symbol error and how do I fix it?
我的网站中有一段代码有问题;此错误仅发生在 Internet Explorer 7 中。 我没有在这里发布我所有的 HTML/CSS 标记,而是发布了网站的一个版本 here . 如您所见,我在列中有
如果尝试在 USB 设备上构建 node.js 应用程序时在我的树莓派上使用 npm 时遇到一些问题。 package.json 看起来像这样: { "name" : "node-todo",
在 Python 中,您有 None单例,在某些情况下表现得很奇怪: >>> a = None >>> type(a) >>> isinstance(a,None) Traceback (most
这是我的 build.gradle (Module:app) 文件: apply plugin: 'com.android.application' android { compileSdkV
我是 android 的新手,我的项目刚才编译和运行正常,但在我尝试实现抽屉导航后,它给了我这个错误 FAILURE: Build failed with an exception. What wen
谁能解释一下?我想我正在做一些非常愚蠢的事情,并且急切地等待着启蒙。 我得到这个输出: phpversion() == 7.2.25-1+0~20191128.32+debian8~1.gbp108
我是一名优秀的程序员,十分优秀!