Failed to save object: path /storage/NFTCollection in account 0XXXXXX already stores an object

Hello everyone, I once deployed the PinataPartyContract on my testnet account then I removed that contract. When I again tried to deploy the same contract, I got this error :

failed to save object: path /storage/NFTCollection in account 0XXXXXXXX already stores an object.

I understand that the user account still contains the collection object. How do I check and destroy it everytime I deploy a new contract. Can you guess provide me with the correct code as I have already tried this

if let oldToken ← acct.load<@KittyItemsMarket.Collection>(from: KittyItemsMarket.CollectionStoragePath) {
destroy oldToken

it does not understand ‘acct.load’,as it only getting deployed on the account first, so it does not get deployed. I guess self.something would be used Please help.

Take a look at the NFT example here:

If the NFT collection resource is destroyed with the destroy command, it needs to know what to do with the resources it stores in the dictionary. This is why resources that store other resources have to include a destroy function that runs when destroy is called on it. This destroy function has to either explicitly destroy the contained resources or move them somewhere else. In this example, we destroy them.

destroy() {
    destroy self.ownedNFTs

Thanks @kimcodeashian :slight_smile: