67 lines
2.8 KiB
Plaintext
67 lines
2.8 KiB
Plaintext
---
|
|
title: Create Database Table Fields
|
|
description: Learn how to create fields/columns in your tables
|
|
page_title: Create Table Fields
|
|
page_description: Define the columns and data types for your Datasquirel tables.
|
|
---
|
|
|
|
## Overview
|
|
|
|
**Fields** (also called columns) define the structure of a SQL table. Every row in the table must conform to the field definitions. Datasquirel provides a visual field editor that maps directly to MariaDB column definitions — what you define is what gets created in the database.
|
|
|
|
## Adding a Field
|
|
|
|
Open a table in your admin panel and click **Add Field** (or access the field editor during table creation). For each field you need to provide:
|
|
|
|
### Field Name
|
|
|
|
The name of the column. Use lowercase letters, numbers, and underscores. This name is used in API responses and SQL queries (e.g. `first_name`, `created_at`).
|
|
|
|
### Data Type
|
|
|
|
The SQL data type for the column. Common types include:
|
|
|
|
| Type | Description |
|
|
|------|-------------|
|
|
| `VARCHAR` | Variable-length text, up to a defined maximum length (e.g. `VARCHAR(255)`) |
|
|
| `INT` | 32-bit integer |
|
|
| `BIGINT` | 64-bit integer — use for IDs that may exceed 2 billion |
|
|
| `TEXT` | Unlimited-length text |
|
|
| `LONGTEXT` | Very large text content (e.g. HTML, Markdown, JSON) |
|
|
| `DATETIME` | Date and time value |
|
|
| `DATE` | Date only |
|
|
| `BOOLEAN` | True/false stored as `TINYINT(1)` |
|
|
| `FLOAT` | Floating-point number |
|
|
| `JSON` | Structured JSON data |
|
|
| `ENUM` | A value from a predefined list |
|
|
|
|
See the full list in the [Database Reference → Data Types](/docs/database-reference/data-types).
|
|
|
|
### Required
|
|
|
|
Check this option to add a `NOT NULL` constraint — the field must have a value on every insert. Leave it unchecked to allow `NULL`.
|
|
|
|
### Default Value
|
|
|
|
A value to use when no value is provided on insert. For example:
|
|
- `0` for numeric fields
|
|
- `""` for empty text
|
|
- `CURRENT_TIMESTAMP` for datetime fields that should auto-populate
|
|
|
|
### More Options
|
|
|
|
Click **More** on any field to access additional options:
|
|
|
|
- **Unique** — adds a UNIQUE constraint so no two rows can have the same value for this field.
|
|
- **Encryption** — encrypts the value before storing it. Useful for sensitive data like tokens.
|
|
- **Foreign Key** — links this field to a column in another table, enforcing referential integrity.
|
|
|
|
## Editing and Removing Fields
|
|
|
|
To edit an existing field, open the table schema editor and click on the field. To remove a field, click the delete icon next to it. Removing a field drops the column from the underlying MariaDB table — all data in that column will be lost.
|
|
|
|
## What's Next
|
|
|
|
- [Create Table Indexes](/docs/gui-reference/databases/create-table-indexes) — add indexes to speed up queries on specific fields
|
|
- [Add an Entry](/docs/gui-reference/databases/add-entry) — start inserting rows
|