<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tomasz Madeyski on Medium]]></title>
        <description><![CDATA[Stories by Tomasz Madeyski on Medium]]></description>
        <link>https://medium.com/@tomasz.madeyski?source=rss-551b567bdec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*DMspBQq8c0ST4nD2uNpMpQ.jpeg</url>
            <title>Stories by Tomasz Madeyski on Medium</title>
            <link>https://medium.com/@tomasz.madeyski?source=rss-551b567bdec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 19:54:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tomasz.madeyski/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[EpiServer model update issue]]></title>
            <link>https://medium.com/@tomasz.madeyski/episerver-model-update-issue-20e09d0f2e?source=rss-551b567bdec------2</link>
            <guid isPermaLink="false">https://medium.com/p/20e09d0f2e</guid>
            <category><![CDATA[episerver]]></category>
            <dc:creator><![CDATA[Tomasz Madeyski]]></dc:creator>
            <pubDate>Wed, 22 Jul 2020 09:13:18 GMT</pubDate>
            <atom:updated>2020-07-22T09:13:18.076Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever faced this EpiServer error?</p><blockquote>The INSERT statement conflicted with the FOREIGN KEY constraint “FK_tblWorkContentProperty_tblPropertyDefinition”. The conflict occurred in database “EPiServer”, table “dbo.tblPropertyDefinition”, column ‘pkID’</blockquote><p>If so, you probably know the pain it brings…</p><h3>Steps to reproduce</h3><p>To get this issue appear you need to have two conditions met:</p><ol><li>You have updated your data model</li><li>You have more than one active instance of EpiServer running (sharing the same database)</li></ol><p>You define your model via code (in most cases), however EpiServer internally reflects this definition in its database.</p><p>When you update your data model:</p><ul><li>add new PageData/BlockData</li><li>add new property to existing PageData/BlockData</li><li>change type of existing property of PageData/BlockData</li></ul><p>EpiServer, by default, on application startup will scan for any changes in the model and will save these changes to database. It will also store model definition in cache so there’s no need to ask database every time when saving new instance of PageData.</p><p>Now, in the scenario you have more than one instance of EpiServer running (our scenario is having separate deployment slot in Azure’s AppService), one instance (deployment slot) updates database on its startup and stores definition in its cache. <strong>The issue is that other instance has its cache not matching new model definition.</strong> If you will try to make changes (on that instance) to page/block of page/block type that has been updated you will get error from the first part of this post.</p><h3>How to avoid issue appear</h3><p>To avoid this issue you need to eliminate precondition of having more than one active instance of EpiServer. EpiServer support, in case you are hosting your solution in their cloud (DXC), <a href="https://support.episerver.com/hc/en-us/articles/115002258032-Episerver-Content-Import-Fails-In-DXC-With-FOREIGN-KEY-Constraint-Error">suggests</a> to make use of “Maintenance page”. This will take you site offline for the time of deployment and display content of static html file you can customize.</p><p>Since EpiServer deployment, startup and warmup can take a while, putting site offline for this time is not good solution…</p><h3>Workaround</h3><p>Source of the issue is that you have your cache outdated so you need to clear this cache. To do so, you can restart your application (IIS/AppService). This is ok locally, but this takes time to warmup EpiServer so it’s not good solution for production site either…</p><h3>Solution</h3><p>A solution we came up with in my project is to do model update “manually”, not on application startup.</p><p>Disabling it on application startup is a matter of changing EpiServer setting (in web.config):</p><pre><strong>&lt;</strong>episerver&gt;<br>  &lt;applicationSettings enableModelSyncCommit=&quot;false&quot;/&gt;<br>&lt;/episerver&gt;</pre><p><strong>TIP</strong>: we kept default setting in regular web.config file as we want this feature to be enabled locally on developer machines. We created web.Release.config transformation to add this attribute before deploying.</p><p>We found a piece of code which is responsible for doing model update and it is EPiServer.Initialization.Internal.ModelSyncInitialization.Initialize() method. Unfortunately code there is written in a way that cannot be reused so we had to copy it from there and create our own custom controller that exposes http endpoint:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d0b6be1d8ef9a6038f5af9f20636492/href">https://medium.com/media/4d0b6be1d8ef9a6038f5af9f20636492/href</a></iframe><p>As you can see it takes relevant parts from EPiServer.Initialization.Internal.ModelSyncInitialization.Initialize() and deals with some issues there, i.e. some classes are marked as internal. As an addition there’s simple check if this method was already called or not as calling this multiple times by some <em>nasty hackers </em>may cause serious performance issues.</p><p>Having this endpoint exposed, we added a step at our Release Pipeline in CI/CD system that calls this endpoint <strong>after </strong>slot is swapped and stopped (so whole process is <em>not-so-manual</em>).</p><p>This way, by moving moment when model is updated, we got rid of error from the top of this post.</p><p>Hope this helps you too!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20e09d0f2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>