Quick Question: How do I avoid ID duplicates when adding records to a database?

I just found out that my workflow creates duplicates every time I delete and add records.

This is the set up:

Is there a way to write that expression in order to avoid duplicates ?

current IDs: 1,2,3,4,5,6,7,

Delete: id: 6,3,7
*add a new category:
Add id: 8

Updated IDs: 1,2,4,5,8

Thank you!

Hi there, @marketing11… if I understand your post correctly, you are likely going to have to save the ID of the last category somewhere other than on the category itself so you can reference that ID and add 1 to it when you create a new category (and then save the new category’s ID to the same place). As you have it right now, there is literally no way for the system to know that the new category’s ID is supposed to be 8 because the count of categories won’t work nor will referencing the ID of the last category (which in your example is 5 because 6 and 7 were deleted).

By the way, just curious… why do you need unique IDs? Are you using them as reference numbers that users can actually refer to in your app? If they don’t have any user-facing value, you might not need them at all, seeing as how Bubble gives every thing a unique ID.

Hope this helps.



As Mike says, you don’t need to do this as all Things already have a unique ID. Every “Equipment Sub Category” is a unique object, even if all of their fields are the same.

Occasionally, someone here insists that they need to give some sort of thing a unique, asymptotically increasing serial number for some (non-technical) reason.

It turns out that Bubble can do this, but it’s tricky and the thread linked below is the definitive word on how to accomplish that. Start with this post, which summarizes the solution:

The whole thread is quite interesting though if you’re very nerdly about Bubble and there’s a classic @keith video in there, to boot.

BUT let me stress that there’s literally no reason to give your Equipment Sub Category object an “id” number. If you want to know what order your Equipment Sub Categorys were created in, just Search for them and sort them by created date.

(Which of course implies that one could— were one really insistent on this—just run those Things sorted in that order through a workflow and later give them numbers like this, but again I fail to see why this is desirable.)


Hi @mikeloc & @keith
Thank you very much for the replies! I really appreciate it.

Here is the problem I’m trying to solve:

I have one db with 15,000 records and 400 columns.

The first 3 columns represent:

Category (300 different categories)
Subcategory (1,500 different subcategories)
Model (the rest of the records)

The other 398 columns, represent the specifications for each subcategory

Specification 1
Specification 2
Specification 3
Specification 4,5,6,…400

However each record only has on average 20-30 specifications/ columns filled based on their subcategory.
The other 300+ columns are totally irrelevant

Problem trying to solve:

Building a form to upload a new record.
The employee only needs to add a name the rest of the info will be taken from the database.

1-.Employee Types the name
2-.Employee Selects category from dropdown
3-. Employee Selects Sub-Category
4-. Base on the selection only (20-40)Specifications auto populate on the specs area so they can get fill by the employee
5-. Employee writes the technical aspects
6-. Submits from and a new record gets created

Since I only need to populate 20-30 columns from those 400 columns, I was trying to build simple unique IDs for the subcategories. So I can save time populating the specs and avoid confusion with the similar sub categories names.

How would you guys solved this issue? (populating the columns that are relevant to each subcategory on the form for the employee to fill)

Thanks again

If you don’t mind me asking why is every Specification in it’s own field instead of storing a list of Specifications? That would make it easier for copying lists of “template” specifications

Are you saying this is how you have your Bubble database set up? You have a Thing with 400 fields on it?

As @tylerboodman implies, this is not how you do it.

Bubble basically stores JavaScript objects and it’s indexed. Those objects (which Bubble calls “Things”) have a Type (you create a name for it) and then those objects have fields which themselves have a data type and the data type can even be some other Thing. Things are referenced by their Unique ID - it’s basically the “primary index” for that unique object. When a Thing has a field of Some Other Thing type, and you store a value there, what you are storing is a reference to that Some Other Thing (its unique ID). And a field might even be a LIST (an array) and so have multiple Things in it, again internally they are simply referenced by their Unique IDs.

So, in your app, you have 300 Categories. Each of these presumably has some number of Subcategories, yes? So here’s what a Category looks like (at a minimum):

And then Subcategories apparently have some number of Specifications on them, so here’s what a Subcategory looks like (at a minimum):

And then you have hundreds of Specifications. You need to make these, just like the individual Category and Subcategory objects you’ve already made. They would look something like this (you don’t say what’s in a “Specification”):

One you create your individual Specifications, you take your individual Subcategory things and populate each Subcategory’s Specification List with the relevant Specifications, but putting each relevant Specification into the Specification List field.

(And of course, obviously we don’t do that in the data tab, we make a little admin page where we can make a better interface for doing so, which seems to be what you’re working on.)

Similarly, for each Category, you will populate its Subcategory List with all of the relevant Subcategory objects.

And now, when a user selects a category, they can see relevant subcategories and when they select one of those, you now know all of the Specifications relevant to that Subcategory.

That’s it. Simple.


BTW, I noticed your Subcategory object has an image type field on it. One should refrain from putting images directly on some Thing unless that Thing really represents an image.

Because you’ve told Bubble that this field is extremely important since it’s at the top level and it will try to download that junk whenever you reference that Subcategory. So don’t do this.

Instead of putting an image in their (I bet this “image” is more of an Icon, right?) you would make another Thing, maybe called “Icon” that has the image field on it, and maybe a field for name, right?

And then you get rid of your “Image” field and replace it with an Icon field of type Icon.

Edit: This is actually very very important because if you don’t this, you’ll be one of those “why is Bubble so slow?” people.


One last thought, when I speak of building an admin interface for populating the database, I’m sort of talking about stuff like the ugly but serviceable interface I build in the following video where I have one list of things from my database and I’m putting those into another list that I then might attach to some other thing.

So exactly what you’re going to have to do to populate your Subcategories with Specs…

See the video linked here:

1 Like

Thank you very much @keith
I really really appreciate your replies. I have no words to describe how thankful I am. You really opened my eyes and taught me a lot.

Thanks for helping the community!

1 Like


Hi Keith, I remember this well, you were very helpful, I’m impressed with how much time you spend helping people - what a legend! I wish bubble would improve their database or just natively connect to mysql (properly I mean) and make it part of their offering.