-
Hello everyone. I have a Migrations.cs file which has the following code block in public async Task<int> CreateAsync()
{
await CreateHomePageContentItemAsync();
await _layerService.CreateHomepageLayerIfNotExistAsync(_conditionIdGenerator);
await CreateMenuAsync();
CreateContentItemByTermIndexTable();
return 1;
}
From my understanding, the three methods before I know that There might be an updating index operation. However, I still can't reason myself why this happened because there is no insert operation to ContentItemByTermIndex table. In addition, I have try to debug YesSql with Source Link but I couldn''t make it work because there is no debugging symbol in YesSql Nuget Note The photo from other project which has Nuget debugging symbol (.snupkg). This error is easy to fix, just move CreateContentItemByTermIndexTable to the top of CreateAsync method's body. However, I just only want to reason why we can't use it as the last method which should be okay because there is no an insert operation to ContentItemByTermIndex table. Here is the link to the source code of the demo project. Exception stack trace: Error while running migration version 0 for 'OrchardIssue1.Theme'.
Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1: 'no such table: ContentItemByTermIndex'.
at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
at Microsoft.Data.Sqlite.SqliteCommand.PrepareAndEnumerateStatements(Stopwatch timer)+MoveNext()
at Microsoft.Data.Sqlite.SqliteCommand.GetStatements(Stopwatch timer)+MoveNext()
at Microsoft.Data.Sqlite.SqliteDataReader.NextResult()
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
at YesSql.Commands.BatchCommand.ExecuteAsync(DbConnection connection, DbTransaction transaction, ISqlDialect dialect, ILogger logger)
at YesSql.Session.FlushAsync()
at YesSql.Session.FlushAsync()
at YesSql.Services.DefaultQuery.Query`1.FirstOrDefaultImpl()
at OrchardCore.Data.Documents.DocumentStore.GetOrCreateMutableAsync[T](Func`1 factoryAsync)
at OrchardCore.Documents.DocumentManager`1.GetOrCreateMutableAsync(Func`1 factoryAsync)
at OrchardIssue1.Theme.LayerServiceExtensions.CreateHomepageLayerIfNotExistAsync(ILayerService layerService, IConditionIdGenerator conditionIdGenerator) in /home/user/projects/orchard-issues/orchard-issue-1/src/Themes/OrchardIssue1.Theme/LayerSeviceExtensions.cs:line 18
at OrchardIssue1.Theme.Migrations.CreateAsync() in /home/user/projects/orchard-issues/orchard-issue-1/src/Themes/OrchardIssue1.Theme/Migrations.cs:line 66
at OrchardCore.Data.Migration.DataMigrationManager.UpdateAsync(String featureId) Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 9 replies
-
I don't know why I think you'll need to populate databases here in a deferred task to ensure that the tables exist file. Try something like this
|
Beta Was this translation helpful? Give feedback.
-
@MikeAlhayek thank you for your suggestion. I know that we have Thanks. |
Beta Was this translation helpful? Give feedback.
-
It failed because no such table: ContentItemByTermIndex' which is my custom index table not Autoroute indexes.
Here is the HomePage content type definition:
I agree that ContentItemByTermIndexProvider will be called whenever there is a new content item but it will insert a new record to a custom index table when a content item that has Thank you so much for your solution and it fix the issue for sure but I still don't think I get the answer. I think in a meantime while waiting for the answer I will create an issue to YesSql to add debugging symbol in a Nuget package. This will help debugging with with Source Link and I can start debugging to YesSql. Thank you so much. |
Beta Was this translation helpful? Give feedback.
-
From memory so not fully sure ;) Yes all registered index providers will be taken into account and the related tables "may" need to already exist. But the index tables are only created at the end of the shell scope executing the migrations, that's why when creating items through migrations we use a deferred task, as I remember we do the same when creating items through recipes. That said what you can try in your index provider, just before the
|
Beta Was this translation helpful? Give feedback.
@jtkech I have updated
ContentItemByTermIndexProvider.cs
to havewhen
filter and it works.Here is then condition in
when
statement.