-2

I'm getting this error while running Update-Database in EF Core:

Arithmetic overflow error converting numeric to data type numeric.
The statement has been terminated.

This SQL segment is also highlighted.

Failed executing 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]'))
SET IDENTITY_INSERT [Drivers] ON;
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'),
(2, '2020-04-30T10:41:02.0000000', -4987412556426210000.0, 419079, N'DRIVER ABUBAKAR', -9141790000000000000.0, '2020-06-01T03:01:34.0000000');

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;

Here is the model class 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; }
}
1
  • 2
    decimal(18,10) means: total nuber of digits=18, out of these 10 after the decimal point; see here.. So you're left with 8 digits before the decimal point which you clearly exceed. Commented Oct 25, 2020 at 6:09

1 Answer 1

0

It looks like you are seeding your database with some data. Possible problems:

  • DriverId and SiteId maybe have incorrect data types specified. You’ve set it do decimal(18,10). That means you only have 8 digits available on the left side of the decimal point. Decimal in general seems strange for an Id field. Usually it’s int or bigint.
  • Your seed data may be incorrect. For example you are trying to insert -9193900000000000000.0 as DriverId. It cannot fit in decimal(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).
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.