如您所见,我正在用一个主键创建一个新类,我删除了数据库以重新创建它,但是public class CustomerContracts{ [Key, Column("ItemId")] //This change the name of the column when you are using migration. If you have a form created already, you have to change the connection in the for to aim the new column name. public int ItemId { get; set; } public string Description { get; set; } public string CustomerRef { get; set; } public int ContractTypeId { get; set; } public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } public bool isActive { get; set; } [DecimalPrecision(18, 2)] public decimal Price { get; set; }}但是,当我尝试更新数据库时,出现以下错误。指定“ -Verbose”标志以查看应用于目标数据库的SQL语句。应用显式迁移:[201804260855058_firstmigration]。应用显式迁移:201804260855058_firstmigration。System.Data.SqlClient.SqlException(0x80131904):为表'CustomerContracts'指定了多个标识列。每个表只允许一个标识列。在System.Data.SqlClient.SqlConnection.OnError(SqlException异常,布尔值breakConnection,操作1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, ActionSystem.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReadS数据状态,BulkStateCopySimpleState,ObjectDataCopyS,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,ObjectState,对象状态,对象状态,对象类型dataReady)位于System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(字符串methodName,布尔异步,Int32超时,布尔asyncWrite)位于System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource 1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at
1 回答
九州编程
TA贡献1785条经验 获得超4个赞
试试这个:
public override void Up()
{
DropPrimaryKey("dbo.CustomerContracts");
DropColumn("dbo.CustomerContracts", "TeamId"); // Drop this first
AddColumn("dbo.CustomerContracts", "ItemId", c => c.Int(nullable: false, identity: true));
AddPrimaryKey("dbo.CustomerContracts", "ItemId");
}
- 1 回答
- 0 关注
- 134 浏览
添加回答
举报
0/150
提交
取消