Forum Academy Marketplace Showcase Pricing Features

Delete a thing from database

I have read others attempts at this but I’m constantly going down a rabbit hole of options. My users can upload one profile photo. How can they delete their image?

Bubble temps me with this being easy, but then I find it’s not!

Here’s what I try;

  1. Create delete button
  2. Create an action of “Delete thing …”
  3. Do a search for … “User” … “'s Image”

So far, all very intuitive … but here’s where it get’s odd…

I then have to choose more options because the text is red. Why? I have said all I need to buy Bubble requires more. Ok …

I try :count (doesn’t work)
I try :first item (nope)
I try virtually all options and nothing works.

1 Like

Looks like you’re using “Delete List of Things” action when you really just want to delete a single thing. Try the “Delete Thing” action.

No, I am using the “Delete Thing” action. Sorry, the image was from when I tried the List (I tried everything!).

The “Delete Thing” action gives an endless list with no end - it always requires you to click another thing or text is red.

You haven’t specified an image to delete here (which is why it’s red)…

Instead you’ve done a search for a list of users’ images, and you’ve left the item number blank.

Assuming your search constraints are returning a single image (the correct one), then just add :first item to specify that it’s an individual image that you want to delete.

If the search is returning multiple users’ images, then you’ll need to specify which one you want to delete (such as item #3 - but that requires knowing where each User is in the list).

If it’s not working then perhaps your search constraints are not properly defined (or there are some privacy rules in place).

If this is an action done by the current user to delete their own image then it may be easier to just Delete the Current User’s Image, rather than doing a search.

1 Like

Yes, it’s to allow the user to delete their own image. But ‘Delete the Current User’s Image’ is not an option. Even the longer ‘:first item’ doesn’t work because it’s ALWAYS red text.

err

This doesn’t work either

Can you screenshot your database model?

Is image an image field or a list of images?

‘Image’ is not a ‘thing’ in your database, so using delete a thing won’t work (there isn’t a thing to delete).

It’s just a field on the User datatype.

So you need to delete the file using the delete an uploaded file action.

As in your screenshot, the expression is blue so it should work fine.

You may also need to ‘erase’ the image field of the user (as it may still refer to the URL of the uploaded image), in which case make changes to the current user and just set the image field to blank.

1 Like

That worked thank you, I would never have figured out to set the image field to blank! You said that ‘Image’ is not a ‘thing’ in your database … what is classified as a ‘thing’? I just assumed anything was a thing!

1 Like

A ‘thing’ is what Bubble calls a database entry.

So if you have a data type of ‘product’ (for example), then each specific product in your database is a ‘thing’.

So you can delete a product using a ‘delete a thing’ action, or make changes to a product using a ‘make changes to a thing’ action etc.

That makes sense, thank you!

1 Like