Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Please help me understand this error

Vote:
 

We had some categories for our pages which we deleted in the code. We are able to compile our project without errors and deploy it to our test instance. Upon restating the test instance however I am greeted with the following error message:

The DELETE statement conflicted with the REFERENCE constraint "FK_tblWorkContentProperty_tblPropertyDefinition". The conflict occurred in database "epicms", table "dbo.tblWorkContentProperty", column 'fkPropertyDefinitionID'.

Can you please help me understand what is going on here? We did not fiddle around with the database. We simply removed some categories from our code as we recently added different ones that are being  used instead.

Below the error on a yellow background I have a stack trace which I was not able to decipher:

[SqlException (0x80131904): The DELETE statement conflicted with the REFERENCE constraint "FK_tblWorkContentProperty_tblPropertyDefinition". The conflict occurred in database "epicms", table "dbo.tblWorkContentProperty", column 'fkPropertyDefinitionID'.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +277
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +765
   System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4239
   System.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows) +253
   System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more) +295
   System.Data.SqlClient.SqlDataReader.TryNextResult(Boolean& more) +344
   System.Data.SqlClient.SqlDataReader.NextResult() +33
   System.Data.ProviderBase.DataReaderContainer.NextResult() +35
   System.Data.Common.DataAdapter.FillNextResult(DataReaderContainer dataReader) +61
   System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue) +253
   System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) +548
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +303
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +181
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +134
   EPiServer.DataAccess.Internal.<>c__DisplayClass27_0.<DeleteDB>b__0() +251
   EPiServer.Data.Providers.Internal.<>c__DisplayClass33_0`1.<ExecuteTransaction>b__0() +61
   EPiServer.Data.Providers.SqlTransientErrorsRetryPolicy.Execute(Func`1 method) +682
   EPiServer.DataAccess.Internal.ContentTypeDB.Delete(ContentType contentType) +108
   EPiServer.DataAbstraction.Internal.DefaultContentTypeRepository.Delete(ContentType contentType) +53
   EPiServer.DataAbstraction.RuntimeModel.Internal.ContentTypeModelRegister.CommitTypes(Boolean deleteUnusedTypes) +148
   EPiServer.DataAbstraction.RuntimeModel.Internal.ContentTypeModelScanner.Sync(Boolean commitChanges) +295
   EPiServer.Initialization.Internal.ModelSyncInitialization.Initialize(InitializationEngine context) +573
   EPiServer.Framework.Initialization.Internal.ModuleNode.Execute(Action a, String key) +58
   EPiServer.Framework.Initialization.Internal.ModuleNode.Initialize(InitializationEngine context) +123
   EPiServer.Framework.Initialization.InitializationEngine.InitializeModules() +257

[InitializationException: Initialize action failed for Initialize on class EPiServer.Initialization.Internal.ModelSyncInitialization, EPiServer, Version=11.10.6.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7]
   EPiServer.Framework.Initialization.InitializationEngine.InitializeModules() +786
   EPiServer.Framework.Initialization.InitializationEngine.ExecuteTransition(Boolean continueTransitions) +194
   EPiServer.Framework.Initialization.InitializationModule.EngineExecute(HostType hostType, Action`1 engineAction) +879
   EPiServer.Framework.Initialization.InitializationModule.FrameworkInitialization(HostType hostType) +187
   EPiServer.Global..ctor() +42
   A1Digital.Site.EPiServerApplication..ctor() +37
   ASP.global_asax..ctor() +42

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +194
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +100
   System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) +1485
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +298
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture) +27
   System.Web.HttpRuntime.CreateNonPublicInstance(Type type, Object[] args) +80
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +182
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +369

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +532
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +114
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +724

#254138
Apr 30, 2021 11:44
Vote:
 

If you can try forcing a restart on the test instance, sometimes the model syncing fails. If this doesn't work try adding the old code back in again, deploying, removing it and republishing 

#254139
Apr 30, 2021 12:49
Vote:
 

Unfortunately we have run into this error more and more recently. It happens after a publish whenever there is a change to a model. We usually just trigger a restart after a deploy and this no longer is an issue.

#254140
Apr 30, 2021 14:34
Vote:
 

Thanks guys, restarting didn't solve the issue. I will try Scotts suggestion and will post back. 

#254143
Apr 30, 2021 15:43
Vote:
 

So I reverted all changes in the code and pushed that branch to our dev instance. I also restarted for good measuer. While the website is working once again, I now have the following strange issue:

When I try to edit a page through the CMS backend, it will show me the content of the page in the "On Page Editing" mode (but wont let me edit anything), but nothing will happen if I try to select the "All Properties" mode (i.e. it will not switch to that view).

Using the log stream I tried to check what the issue could be and found the following error which seems to be relevant to this case?

System.NullReferenceException: Object reference not set to an instance of an object.
   at A1Digital.Site.Helpers.Selections.DataLayerCoreStorySelectionFactory.GetSelections(ExtendedMetadata metadata)
   at EPiServer.Shell.UI.Rest.DefaultMetadataStoreModelCreator.GetSelections(ExtendedMetadata metadata, MetadataStoreModel metadataDTO, ISelectionFactory[] selectionFactories)
   at EPiServer.Shell.UI.Rest.DefaultMetadataStoreModelCreator.CreateFromModelMetadata(ExtendedMetadata metadata, LocalizationService localizationService, UIDescriptorRegistry uiDescriptorRegistry, ISelectionFactory[] selectionFactories, Boolean alwaysCreateChildProperties)
   at EPiServer.Shell.UI.Rest.DefaultMetadataStoreModelCreator.ExtractMetadataFromProperties(ExtendedMetadata metadata, MetadataStoreModel MetadataStoreModel, LocalizationService localizationService, UIDescriptorRegistry uiDescriptorRegistry, ISelectionFactory[] selectionFactories)
   at EPiServer.Shell.UI.Rest.DefaultMetadataStoreModelCreator.CreateFromModelMetadata(ExtendedMetadata metadata, LocalizationService localizationService, UIDescriptorRegistry uiDescriptorRegistry, ISelectionFactory[] selectionFactories, Boolean alwaysCreateChildProperties)
   at EPiServer.Shell.UI.Rest.DefaultMetadataStoreModelCreator.Create(ModelMetadata metadata)
   at EPiServer.Shell.UI.Rest.MetadataStore.Get(String id, String modelAccessor)
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3d()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.b__3f()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.b__3f()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.b__3f()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.b__1c()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.b__1e(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
   at EPiServer.Shell.Services.Rest.RestControllerBase.EndExecute(IAsyncResult asyncResult)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)"

The error above mentions "DataLayerCoreStorySelectionFactory" which is one of the Selection Factories that I had deleted. Since I reverted to a previous version of the code, this Selection Factory is back in the code that I pushed to our dev instance.

Also in the log stream I am seeing such errors:

EPiServer.DataAccess.Internal.ContentDB : Content with id '933_46269' has a property with scopename '1589' but there is no entry in IPropertyDefinitionRepository with that id,

Hoping you guys have some other suggestions for me to try?

I am relatively new to EpiServer and ASP .NET but I did not consider deleting categories from the code to end up being this complicated. I come from the Wordpress corner of the web and expected this to be a walk in the park :-(

#254217
Edited, May 02, 2021 10:01
Vote:
 

I went ahead and replaced the DB of our Dev instance with that of our Staging instance. The error no longer shows up and I am able to edit pages through the backend. I still don't understand what happened though but at least I can continue working this way. 

#254255
May 03, 2021 10:06
Vote:
 

As when you deploy code it goes through a syncing process this will be modifying the stucture of the database so there's a few things to keep in mind.

  1. Always have a database backup ready when deploying to an environment in case of rollback
  2. Make sure you version your assemblies as part of it's content sync it looks to do it if you're deploying a higher version so roll up and roll back can get confused if you don't
  3. If there's anything complex you can create classes to handle the data migration. Say if you're migrating complex types and you have to re-save the structure.

But glad it's working again

#254328
May 04, 2021 8:30
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.