Open Closed

DB Migration error #642


User avatar
1
shobhit created

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

  • ABP Framework version: v4.0.0
  • UI type: Angular
  • Tiered (MVC) or Identity Server Seperated (Angular): yes
  • Exception message and stack trace:
* An exception occurred while iterating over the results of a query for context type 'Volo.Abp.IdentityServer.EntityFrameworkCore.IdentityServerDbContext'.
System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
   at Microsoft.Data.SqlClient.SqlBuffer.ThrowIfNull()
   at Microsoft.Data.SqlClient.SqlBuffer.get_Boolean()
   at Microsoft.Data.SqlClient.SqlDataReader.GetBoolean(Int32 i)
   at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.BufferedDataRecord.ReadBool(DbDataReader reader, Int32 ordinal, ReaderColumn column)
   at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.BufferedDataRecord.ReadRow()
   at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.BufferedDataRecord.InitializeAsync(DbDataReader reader, IReadOnlyList`1 columns, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.InitializeAsync(IReadOnlyList`1 columns, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.InitializeAsync(IReadOnlyList`1 columns, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
   at Microsoft.Data.SqlClient.SqlBuffer.ThrowIfNull()
   at Microsoft.Data.SqlClient.SqlBuffer.get_Boolean()
   at Microsoft.Data.SqlClient.SqlDataReader.GetBoolean(Int32 i)
   at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.BufferedDataRecord.ReadBool(DbDataReader reader, Int32 ordinal, ReaderColumn column)
   at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.BufferedDataRecord.ReadRow()
   at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.BufferedDataRecord.InitializeAsync(DbDataReader reader, IReadOnlyList`1 columns, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.InitializeAsync(IReadOnlyList`1 columns, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.InitializeAsync(IReadOnlyList`1 columns, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()

D:\Projile\ABP-Suite\aspnet-core\src\Ezpand.DbMigrator\bin\Debug\net5.0\Ezpand.DbMigrator.exe (process 13132) exited with code -1.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
  • Steps to reproduce the issue:

Migrating current applicaiton from 3.3.1 to 4.0.0. Not able to run DBMigration service. Getting exception as above.


25 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi shobhit

    Identity Server 4 has a lot of breaking changes, have you applied to your project?

    https://docs.abp.io/en/abp/latest/Migration-Guides/Abp-4_0#upgraded-to-identity-server-4-1-1

  • User Avatar
    0
    shobhit created

    yes. i hope so. I have followed same document.

  • User Avatar
    0
    shobhit created

    Hello maliming, Can you help me in the quick manner as i have upgraded my project and it is not running so i have all deliverable pending, Also ABP suite is also not working even if i do roll back. Please help.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can create a new project of version 4.0. Then compare the code.

    If possible you can provide me with a project, I can download and check to it. liming.ma@volosoft.com

    How can I install a specific version of ABP Suite?

    https://support.abp.io/QA/Questions/287/How-can-I-install-a-specific-version-of-ABP-Suite

  • User Avatar
    0
    shobhit created

    Hello maliming, Will creating new project only need code migration or even db migration. if both then i cannot do it. If it need only code then we can try. confirm.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    I hope I can reproduce your problem. So I can check and solve it.

    Please provide the project or code.

  • User Avatar
    0
    shobhit created

    can we do screen share. Before sharing code i will need all various approvals.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I can remotely check it by zoom tomorrow. (UTC +8) liming.ma@volosoft.com

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can consider deleting all migrations and then adding a new one. You can delete the Migrations folder.

    Please backup the database before trying.

    Re-adding the migration will solve your problem.

    This is a simple way, otherwise I need to get the source code of your project to check.

  • User Avatar
    0
    shobhit created

    Please share the steps. will follow. consider i will create new database

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Please back up the code and database.

    1. delete the Migrations folder.
    2. run dotnet ef migrations add Initialcommand in xxx.EntityFrameworkCore.DbMigrations folder.
    3. run dotnet ef database update command or run xxx.DbMigrator to apply.

    https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/

  • User Avatar
    0
    shobhit created

    As per instruction. 1- i have created new database 2- deleted migration folder 3- run "dotnet ef migrations add myproject" command 4- it generated migration folder again 5- run the "DBMigrator" 6- Error: Failed executing DbCommand (439ms) [Parameters=[@__providerName_0='?' (Size = 64)], CommandType='Text', CommandTimeout='30'] SELECT [a].[Id], [a].[Name], [a].[ProviderKey], [a].[ProviderName], [a].[Value] FROM [AbpSettings] AS [a] WHERE ([a].[ProviderName] = @__providerName_0) AND [a].[ProviderKey] IS NULL [14:42:25 ERR] An exception occurred while iterating over the results of a query for context type 'Volo.Abp.SettingManagement.EntityFrameworkCore.SettingManagementDbContext'. Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid object name 'AbpSettings'.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi @shobhit

    Can you reproduce the problem in the 4.0 template project? Because I see you are using different connection strings for different modules.

    https://docs.abp.io/en/abp/latest/Entity-Framework-Core-Migrations

  • User Avatar
    0
    shobhit created

    i have removed all connection string and having only Default now but still same issue.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi shobhit

    Can you reproduce the problem in the 4.0 template project? You can try it. In that way I can quickly locate the problem.

  • User Avatar
    0
    shobhit created

    i have created new 4.0 project and run the DBMigrator. It is running as expected.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I mean can you find some differences between your project and the template project that might be causing the problem.

    That is, if you copy some code of your project to the template project, the above problem occurs.

  • User Avatar
    0
    shobhit created

    Oh then i have to copy lot of stuff. it is simply like creating new project.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    If I cannot reproduce the problem, I cannot solve the problem. : (

  • User Avatar
    0
    shobhit created

    Ok.

    So as per suggestion i have created new ABP4.0 project. I run the DBMigrator and it has created the fresh db schema. Now when i am running DBMigrator again it is throwing error:

    [22:26:00 INF] Started database migrations... [22:26:00 INF] Migrating schema for host database... [22:26:05 ERR] Failed executing DbCommand (367ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] CREATE TABLE [AbpAuditLogs] ( [Id] uniqueidentifier NOT NULL, [ApplicationName] nvarchar(96) NULL, [UserId] uniqueidentifier NULL, [UserName] nvarchar(256) NULL, [TenantId] uniqueidentifier NULL, [TenantName] nvarchar(max) NULL, [ImpersonatorUserId] uniqueidentifier NULL, [ImpersonatorTenantId] uniqueidentifier NULL, [ExecutionTime] datetime2 NOT NULL, [ExecutionDuration] int NOT NULL, [ClientIpAddress] nvarchar(64) NULL, [ClientName] nvarchar(128) NULL, [ClientId] nvarchar(64) NULL, [CorrelationId] nvarchar(64) NULL, [BrowserInfo] nvarchar(512) NULL, [HttpMethod] nvarchar(16) NULL, [Url] nvarchar(256) NULL, [Exceptions] nvarchar(4000) NULL, [Comments] nvarchar(256) NULL, [HttpStatusCode] int NULL, [ExtraProperties] nvarchar(max) NULL, [ConcurrencyStamp] nvarchar(40) NULL, CONSTRAINT [PK_AbpAuditLogs] PRIMARY KEY ([Id]) );

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    The reason for this situation may be that the __EFMigrationsHistory table is empty after the first execution of DBMigrator.

  • User Avatar
    0
    shobhit created

    so what is the solution in this case.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you check the __EFMigrationsHistory table of the database after you exec the migration? Generally this does not happen.

  • User Avatar
    0
    shobhit created

    cannot understood. what exactly i should check in __EFMigrationsHistory and what i should do to make sure the ABP suite runs???

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    The problem cannot be reproduced. If you can reproduce the problem, please reopen it.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 05, 2024, 12:19