We are in the process of developing our first implementation in DXC. In the past we have hosted everything on promise and are used to having more access to the database/servers. This allowed us to run scripts manually when we need to clean data, or make large changes. The DXC environment is a bit of a different animarl andm we have created a data project with Entity Framework for custom tables, and kept all SQL run as Entity Framework migrations as Johan suggested.
This has worked well until we needed to change a property type in one of our commerce models.
Our EF migrations do not run until after Episerver Framework Initilization runs which results in us receiving the dreaded "A meta field with the same name as the property 'XYZ' exists, but has another data type" error.
There is no way - at least officially - to run code before the initialization modules. However the problem as I see it is that you are having inconsistent data model. You did not copy the entire error message, but you seem to have two properties in two different content types with same name, but different types. That should be corrected.
Correct The complete error message:
A meta field with the same name as the property 'PrimaryImage' exists, but has another data type. Property type: ShortString. Meta field type: URL.
at EPiServer.Commerce.Catalog.Provider.Construction.CatalogContentScannerExtension.CreateOrUpdateMetaField(MetaClass metaClass, PropertyDefinitionModel propertyDefinitionModel)
at EPiServer.Commerce.Catalog.Provider.Construction.CatalogContentScannerExtension.AssignModelPropertiesToMetaClass(MetaClass metaClass, IEnumerable`1 propertyDefinitionModels)
at EPiServer.Commerce.Catalog.Provider.Construction.CatalogContentScannerExtension.AssignValuesToProperties(ContentTypeModel contentTypeModel)
at EPiServer.DataAbstraction.RuntimeModel.Internal.ContentTypeModelScanner.AssignValuesToProperties(ContentTypeModel modelType)
at EPiServer.DataAbstraction.RuntimeModel.Internal.ContentTypeModelScanner.AddModel(Type type)
at EPiServer.Initialization.Internal.ModelSyncInitialization.Initialize(InitializationEngine context)
at EPiServer.Framework.Initialization.Internal.ModuleNode.Execute(Action a, String key)
at EPiServer.Framework.Initialization.Internal.ModuleNode.Initialize(InitializationEngine context)
We can fix this by running a sql script, but are looking for the best way to do this going forward with the DXC environment. Hopefully this won't happen often and it should only be during our main development. I was mostly wondering if there is a best practice when handling this situation in restricted environments.
You can go to Commerce Manager and delete the metafield manually. The catalog content type will be re-synchronized when you restart the site.
Of course if you want to keep the data in that metafield, it will be tricky. In such case you'd have to contact developer support service - I'm not allowed to say the trick here.
Sometimes when you have faulty data, direct data manipulation is needed, but that should not be done without a close examination of data.