Umbraco 13 to 17 upgrade - premigration error

Hi there, I’m trying to upgrade a project from 13.15.0 to 17.5.1 .

All the packages update and the project builds as exspected, but after the migration starts to run I’m hitting this error in the browser, with an Umbraco failed to boot message:

 An error occurred while running the premigration upgrade.
The database configuration failed with the following message: 
There are no primary or candidate keys in the referenced table 
'umbracoNode' that match the referencing column list in the 
foreign key 'FK_umbracoUserGroup2GranularPermission_umbracoNode_uniqueId'.
Could not create constraint or index. See previous errors.
Please check log file for additional information
 (can be found in 'LoggingSettings.Directory')

I’ve tried running this query, but I think this is for constraints being untrusted rather than not being created (Untrusted Database Constraints | CMS 17.latest (LTS) | Umbraco Documentation):

       OBJECT_NAME(fk.parent_object_id) AS TableName, fk.name AS ConstraintName
FROM sys.foreign_keys fk
INNER JOIN sys.schemas s ON fk.schema_id = s.schema_id
WHERE fk.is_not_trusted = 1
  AND (OBJECT_NAME(fk.parent_object_id) LIKE 'umbraco%' OR OBJECT_NAME(fk.parent_object_id) LIKE 'cms%')

UNION ALL

SELECT 'Check constraint', s.name,
       OBJECT_NAME(cc.parent_object_id), cc.name
FROM sys.check_constraints cc
INNER JOIN sys.schemas s ON cc.schema_id = s.schema_id
WHERE cc.is_not_trusted = 1
  AND (OBJECT_NAME(cc.parent_object_id) LIKE 'umbraco%' OR OBJECT_NAME(cc.parent_object_id) LIKE 'cms%');

Has anyone come across this before?

Thanks

Hi @si25

It sounds like the index on umbracoNode.uniqueId is missing.

Can you check if you have this index, and if not can you create it?

CREATE UNIQUE NONCLUSTERED INDEX [IX_umbracoNode_uniqueID] ON [umbracoNode] ([uniqueId] ASC);

If it is missing, it would be a bit worrying, although the chance of a duplicate GUID being created would be very slim.

You could create a blank v17 instance and compare the tables/keys/indexes to see if you are missing anything else. There may have been a failed migration somewhere along the lines…

Justin

Thanks @justin-nevitech appreciate it, that’s been a really useful starting point

Those keys are missing and creating an index DOES work, though I’m also a little unsure whether doing so manually will create any unexpected db issues in production…

Interestingly FX_umbracoUserGroup2GranularPermission is a v14 db addition, so testing v13 - v14 migration in case that gets it working :crossed_fingers:

Hi @si25

That was an index definition from a v17 project, so it should be the default one Umbraco has - why you are missing it I’ve no idea? It shouldn’t cause any problems.

You should be able to go from LTS to LTS, so you should only need to update using the v17 project - you shouldn’t need v14 as an interim step. If that’s not the case for you then by all means see if v14 works.

Let us know how you get on.

Justin

In case anyone else comes across this issue, @justin-nevitech was on the money with creating an index manually :raising_hands:

Using this full index definition has worked for me (usual caveats about backing up and testing any database changes thoroughly):

CREATE UNIQUE NONCLUSTERED INDEX [IX_umbracoNode_UniqueId] ON [dbo].[umbracoNode]
(
	[uniqueId] ASC
)
INCLUDE([parentId],[level],[path],[sortOrder],[trashed],[nodeUser],[text],[createDate]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO

Sounds as if the index was introduced in v8 for new installs, but no migration was ever added, so if a database has been upgraded since v7 this could be why its missing.

It was actually part of the 7.3.0 update for ids becoming guids..

Umbraco-CMS/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/UpdateUniqueIdToHaveCorrectIndexType.cs at release-7.15.11 · umbraco/Umbraco-CMS

So looks like an incomplete/missed migration somewhere along the road.. :thinking:

hmm that’s interesting, thanks Mike. There’s not much of a paper trail before I took the project over in v8, but certainly looks like a migrations been missed here :grimacing:

Running this query isn’t returning any records, which (hopefully :crossed_fingers:) suggests that there hasn’t been any data integrity issues:

SELECT uniqueId, COUNT(*) FROM umbracoNode GROUP BY uniqueId HAVING COUNT(*) > 1;

If you are worried about data integrity in the DB.. you could perhaps do a clean uSync Export, replace your DB with a vanilla DB from a 17 blank install and then reimport from uSync?

But might not be as simple as all that, depending on the requirements to maintain audittrails, members, uForm entries etc…

And if it isn’t currently broken… then do you need to fix it! :face_with_peeking_eye:

Yeah its the audit trails which are a bit of a pain, others in the business are pretty set on needing them - thanks for the suggestion though!

You’re right, there’s nothing to suggest it is broken so best to leave as is. Think any manual updates needed on the db gives me the fears :sweat_smile:

If you need to maintain audit trails watch out for the automatic version cleansing in the later versions of umbraco… though I’m sure you’re already aware :wink: