简体   繁体   English

运行更新数据库 EFCore 时出现算术溢出错误

[英]Arithmetic Overflow Error When running Update-Database EFCore

I'm getting this error while running Update-Database in EF Core:在 EF Core 中运行Update-Database出现此错误:

Arithmetic overflow error converting numeric to data type numeric.将数字转换为数字数据类型时出现算术溢出错误。
The statement has been terminated.该语句已终止。

This SQL segment is also highlighted.此 SQL 段也突出显示。

Failed executing DbCommand (10ms) [Parameters=[], CommandType='Text', CommandTimeout='30']执行 DbCommand 失败 (10ms) [Parameters=[], CommandType='Text', CommandTimeout='30']

IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DiverId', N'CreatedAt', N'DriverId', N'EmployeeNumber', N'Name', N'SiteId', N'UpdatedAt') AND [object_id] = OBJECT_ID(N'[Drivers]')) IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DiverId', N'CreatedAt', N'DriverId', N'EmployeeNumber', N'Name', N'SiteId', N 'UpdatedAt') AND [object_id] = OBJECT_ID(N'[Drivers]'))
SET IDENTITY_INSERT [Drivers] ON; SET IDENTITY_INSERT [驱动程序] ON;
INSERT INTO [Drivers] ([DiverId], [CreatedAt], [DriverId], [EmployeeNumber], [Name], [SiteId], [UpdatedAt]) INSERT INTO [Drivers] ([DiverId], [CreatedAt], [DriverId], [EmployeeNumber], [Name], [SiteId], [UpdatedAt])
VALUES (1, '2020-04-30T10:41:02.0000000', -9193900000000000000.0, 119642, N'WDE274YE TOCHUKWU', -9141790000000000000.0, '2020-06-01T03:01:34.0000000'),值 (1, '2020-04-30T10:41:02.0000000', -9193900000000000000.0, 119642, N'WDE274YE TOCHUKWU', -914179000000003:0000000040000000004
(2, '2020-04-30T10:41:02.0000000', -4987412556426210000.0, 419079, N'DRIVER ABUBAKAR', -9141790000000000000.0, '2020-06-01T03:01:34.0000000'); (2, '2020-04-30T10:41:02.0000000', -4987412556426210000.0, 419079, N'DRIVER ABUBAKAR', -91417900000000000020.01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000次

IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DiverId', N'CreatedAt', N'DriverId', N'EmployeeNumber', N'Name', N'SiteId', N'UpdatedAt') AND [object_id] = OBJECT_ID(N'[Drivers]')) IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DiverId', N'CreatedAt', N'DriverId', N'EmployeeNumber', N'Name', N'SiteId', N 'UpdatedAt') AND [object_id] = OBJECT_ID(N'[Drivers]'))
SET IDENTITY_INSERT [Drivers] OFF; SET IDENTITY_INSERT [驱动程序] 关闭;

Here is the model class Driver :这是模型类Driver

public class Driver 
{
        public int Id { get; set; }
        public DateTime CreatedAt { get; set; }
        public DateTime UpdatedAt { get; set; }
        [Column(TypeName = "decimal(18,10)")]
        public decimal SiteId { get; set; }
        [Column(TypeName = "decimal(18,10)")]
        public decimal DriverId { get; set; }
        public string Name { get; set; }
        public int EmployeeNumber { get; set; }
}

It looks like you are seeding your database with some data.看起来您正在用一些数据为数据库做种。 Possible problems:可能的问题:

  • DriverId and SiteId maybe have incorrect data types specified. DriverId 和 SiteId 可能指定了不正确的数据类型。 You've set it do decimal(18,10).您已将其设置为十进制(18,10)。 That means you only have 8 digits available on the left side of the decimal point.这意味着小数点左侧只有 8 位可用数字。 Decimal in general seems strange for an Id field.对于 Id 字段,十进制通常看起来很奇怪。 Usually it's int or bigint.通常它是 int 或 bigint。
  • Your seed data may be incorrect.您的种子数据可能不正确。 For example you are trying to insert -9193900000000000000.0 as DriverId.例如,您试图插入 -9193900000000000000.0 作为 DriverId。 It cannot fit in decimal(18,10).它不能适合十进制(18,10)。 This is the largest decimal(18,10) number: 99999999.9999999999 (18 digits in total, but 10 digits reserved for the part after the decimal point).这是最大的十进制(18,10)数:99999999.9999999999(共18位,但小数点后部分保留10位)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行更新数据库实体框架时出错2 - Error running update-database entityframeworkcore 2 为MySql数据库运行更新数据库时出错:表'xxx'不存在 - Getting error when running update-database for MySql database: Table 'xxx' doesn't exist 使用Entity Framework,Code First(POCO)和Code Contracts运行Update-Database时出错 - Error When running Update-Database using Entity Framework, Code First (POCO) and Code Contracts 在MVC5中运行Update-Database时出错 - Error while running Update-Database in MVC5 运行代码第一次迁移update-database时出错 - Error running code first migration update-database 使用更新数据库命令MVC 4时出错 - Error when using Update-Database command MVC 4 尝试首先更新数据库代码时出错 - Error on trying to Update-Database code first 实体框架6中“更新数据库”之后发生错误 - Error after 'update-database' in Entity Framework 6 DbContext继承更新 - 数据库错误 - DbContext inheritance update-database error 为什么我在运行更新数据库时得到 Object 引用未设置为 object 的实例 - Why do I get Object reference not set to an instance of an object when running Update-Database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM