Episerver tends to err on the side of caution in scenarios like this to avoid deletion of data based on Attribute changes for Content Types.
CMS Content Types have a little more information provided if you view them through the Admin mode - they will tell you when properties are removed from code, or which ones originated in the database and let you make a decision to clean them up.
For Commerce Content types, you need to go into Commerce Manager and remove the underlying Metafield from the Metaclass associated with your Content Type. Commerce Content Types were added later and are simply a wrapper around defining those Metaclasses and Metafields. This should remove that connection and prevent it from being rendered in the UI. Depending on your version of Commerce, it may still exist in the database after that removal and you may need to perform manual cleanup if that is part of your requirements.
Hope this helps,
Matthew is totally correct. The reason was a metafield does not have to strictly map 1:1 with a property. This allows you, for example, to import a catalog without having to define the strongly typed content types and their properties. The downside is, of course, the metafield will not be automatically deleted when you delete a property - it's very hard to know if the delete is intentional or not (in other words it's very unsafe to do so).
In Commerce 9 or later, unlink a metafield from a metaclass will not delete the data automatically, you will have to do it yourself (it would still be safe if you leave them there, for an experimental metafield, I don't expect much of garbage data. But if you really really want to clean your DB up, look at ecfVersionProperty and CatalogContentproperty table). In prior versions, unlink a metafield will automatically delete the data as the column is dropped from the metaclass table.
I'm having a similar problem I think that I can't seem to solve. I have a bunch of properties that were refactored in the code to have different property names, and some that were deleted altogether (example, on the content tab there is a description longstring text area as expected, but also a description string text box which is not in the model class) Some of the properties are still appearing in Commerce Manager in the Meta Classes area and in the Episerver Catalog. I am using Commerce Version: 9.19 (build: 1) by the way.
I cannot see a delete button on the classes except for the one at the bottom which says you need to tick the properties to delete, but when I try this I get an error screen saying:
The DELETE statement conflicted with the REFERENCE constraint "FK_CatalogContentProperty_MetaClass". The conflict occurred in database "CompanyABCCommercedb", table "dbo.CatalogContentProperty", column 'MetaClassId'.
Step 1. Create SQL Code
Step 2. Drop operation
The statement has been terminated.
Any help would be greatly appreciated.
I'm not sure I understand your problem. So:
- You have bunch of metaclasses and metafields before
- You refactor them in the catalog content model types.
- You want to remove the left behind metaclasses/metafields?
If that's true, then you are into dangerous terrority - when some database manipulation must be needed. We generally recommend to avoid such things, because it is simply dangerous, and is not supported by Episerver. The remaining data should be harmless anyway.
However, if you still want to go, I would suggest:
- Backup your site, entirely
- Backup your databases.
- Look at the [CatalogContentProperty] table. You can delete rows with MetaClassId = Id of the metaclass you want to remove. After that you should be able to delete the MetaClass.
Again, this is not recommended and you're on your own for such thing. Good luck.
Yes that sounds like you have understood correctly. Is there any other alternative, for example hide the properties so they dont show on the screen but might still exist? Because some of the old properties were required fields it means I have to type something into a field that isnt used anywhere, which is confusing for the user. The system I am working on is still in development, so the small amount of data stored in the catalog could be replaced if necessary.
Here is a screenshot of what I am talking about
https://img42.com/XIh7E (expires in 30 mins)
You can always "unlink" a property (metafield) from a model type (metaclass). Go to the Commerce Manager Administration section => Catalog => MetaClass => Select the type of class (Node or Entry), then select the MetaClass you would like to edit. Then uncheck the properties you don't want to be in the MetaClass, then click OK to save.
I think I might be able to avoid touching the database by unlinking. It was just never explained as clearly before, so thank you.
For testing purposes I have created some properties on a product:
Then i build my project, and the property show up when I go to the sites Commerce Catalog - This is expected and is what should happen.
My problem is the other way around, when I delete the property again (from code) and then build my project.
The property is still present in the Commerce Catalog - but obviously not in code.
I believe the problem might be that the database still see the property and is not updated correctly to see that the property is gone.
Does anyone have a fix to this problem? Maybe a way to force the database to see what properties I actually have in my code?