Data types and fields
This section covers what data types are and how you can set up custom types of data with fields holding different kinds of information
Last updated
This section covers what data types are and how you can set up custom types of data with fields holding different kinds of information
Last updated
We also have multiple guides on how to set up your database structure based on what kind of app you are building. You can take a look at these in our article series on Database structure by app type.
The database consists of different data types that you as the developer plan and set up. Data types are like containers that hold specific types of information and each data type is made up of fields where that information is stored.
For example, in a sports league management system, one data type might be used to hold information about teams, such as their name, coach, and roster of players. Another data type could be used to hold information about games, such as the date, location, and final score.
With our visual editor, you have complete freedom to structure, manage, and connect data types as you want.
Let's first have a look at how you create new data types:
You can create as many data types as you need. To create one, follow the steps below:
First, navigate to the Data tab in the Bubble editor
Then, go to Data types
In the field labelled New type, provide a name. Don't worry, you can this at any later time.
Click the Create button
The new data type will be added to the Custom data types list.
Bubble lets you name your Data Types as you please, even using characters such as space. While you are free to name them as you please, it can be useful to follow a few guidelines:
Use unique names: While Bubble does support duplicate names, giving your data types unique names makes it easier to identify the correct one. Keep in mind that this can affect as well, as Option sets and data types will often show up in the same lists.
Use singular names: Bubble automatically pluralizes names. For example, if you name your data type Event, Bubble will automatically refer to it as Events whenever it's appropriate
Each data type consist of fields that hold different kinds of information. These fields are formatted in specific ways and can only hold the type of information that they are set up to contain.
To illustrate, think of a phone book: a Contact has different fields for name, date of birth and email address and the format of these fields remains constant: name and email address will always contain text and date of birth will always contain a date.
The field is where the information saved to a data type is actually stored.
Bubble has the following built-in field types:
text A string a text that can contain any kind of character
number A numerical value, which can be a whole number or a decimal
numeric range A range consisting of a low and a high value, such as 5-10
date Contains a date and time
date range A range of dates, such as 1/1/1970 - 1/15/1970
date interval A Date interval quantifies the difference between two dates. It/s the number of days/hours/minutes/etc between them
yes / no A value that can be true or false (sometimes called a boolean)
file The URL of a file
image The URL of an image file
geographic address A Google Maps formatted address
Data type Any data type that you can set up can also be a field type
This is where the flexibility of Bubble's database becomes apparent: by creating custom data types and populating those types with custom fields, we can set up a structure for almost any thinkable scenario.
The last item on the list above is particularly significant. That's because every data type we create can be used to format a field in a different data type, which is how we interconnect them.
Each field can also be set up to store a list of values. For example, if you want to store more than one text value you can check the box labelled This field is a list (multiple entries). This lets you add new values that make up a list, such as Red, Blue, Green, Yellow.
Any type of field can contain lists, including custom data types. This way you can reference multiple things, such as the tags connected to a blog post or the products in a cart.
In addition to the fields that you choose to add to a data type, Bubble will also set up the fields below:
The Unique ID is a 32-character string that identifies a specific in your database. The Unique ID (sometimes shortened to UID) is generated automatically when the thing is created and cannot be edited.
A Unique ID looks like the example below:
These two fields are also automatically populated by Bubble and are stored in the date format. The Date created field never changes, and the Date modified field automatically updates any time any changes are made to the Thing.
The slug field lets you set up a user-friendly and search engine optimized URL for the thing. When you , you can instruct Bubble to use this string of text as the last part of the page's URL, to give each thing a unique URL.
For example, if the name of a Product is "A Beginner's Guide to Bubble," the corresponding slug might be "a-beginners-guide-to-bubble". The slug is then appended to the page URL such as:
This lets you set up user-friendly and search engine optimized URLs for different data types such as articles, blog posts, products, and other types of content.
Changing the slug on a thing cannot be done with the action, but needs to be done with the action.
Any data type that you create can also be used as a field type. For example, say you have a data type called Cart, and to this cart you should be able to add Products. You can set up a field on the Cart data type, check This field is a list and choose the Product data type as Field type:
For instance, we can use a data type for a shopping cart to connect it to a data type for a user. By doing that, we can determine who the owner of that particular cart is.
After you have created your data type, you can set up the fields you need:
First, select the data type on which you want to create a new field (Cart)
Click the Create a new field button at the bottom of the existing fields
Give the field a fitting name
Choose the type of data you want to store in that field from the list above or from your existing data types. In this example we have selected User since we want the owner of the Cart to be a registered user
Pick whether the field should contain a list of the selected data or a single item. In this case we want each cart to just have one owner, so we don't check the box.
Let's look at some examples of how varying app types may require different data types:
We'll go over three different examples to see how you can set up data types that cater to different applications. Note that the examples aren't intended to be a blueprint or the best practice for these categories. Instead, they serve to demonstrate the versatility of data types in various scenarios.
In an eCommerce store, we might need three data types to handle basic functionality. We want Users to be able to add Products to a Cart:
Product
Cart
User (built in)
Managing a sports league could require a bit more complicated setup: a league consists of different Clubs, that each have a few Teams with Players. The players play Games. The Player data type is actually the built-in User data type. Since Bubble already provides this data type that allows users to log in and use the app, it makes sense to use it. Keep in mind that the User data type cannot be renamed. Therefore, we're simply clarifying that it's referred to as a Player in this particular context.
League
Club
Team
Game
Player (user - built in)
A blog can have a very simple setup consisting of blog posts, tags that let you search for posts of a specific type and authors. Again, the Author type is the User type but to better convey its intended purpose, it's referred to as "Author"
Blog post
Tags
Author (user - built in)
Product
Name (text) Description (text) Image (image) Price (number)
Cart
Owner (user) Products (list of Products)
User (built in)
Name
In our Sports league management app we can really see how data types are referenced downward in the hierarchy: a Player is a part of a Team, which is a part of a Club, which is a part of a League.
League
Name (text)
Club
Name (text) League (League)
Team
Name (text) Club (Club)
Player (user - built in)
Name Email (built-in) Team (Team)
On our blog website we can return to a simpler structure. We have the blog posts, on which we need to store 1) the header and post content, both texts, 2) The User who wrote it (the author) and the list of Tags (such as Politics and Tech).
Blog post
Header (text) Post (text) Author (User) Tags (list of Tags)
Tag
Name
Author (user - built in)
Name Email (built-in)
As we've explored, setting up custom data types and fields lets you adapt your database to suit your project. In simple terms, data types are the containers that define the type of data you want to manage, while fields contain the various types of information stored within that data type.
If we were working on a phone book, the data type would be Contact and the fields would Name, Email address and Phone number.