content/influxdb3/cloud-serverless/admin/buckets/manage-explicit-bucket-schemas.md
[!Warning]
Don't use explicit schemas with InfluxDB 3
Don't use explicit bucket schemas with InfluxDB 3. The sections on this page provide help for managing and troubleshooting
explicitbuckets you may already have.
In InfluxDB 2.x, buckets with the explicit schema-type use
explicit bucket schemas to ensure measurements have specific columns and data types and to prevent non-conforming writes.
When testing an explicit schema, start by trying to write data that doesn't conform to the schema and that the bucket should reject.
To ensure your schema is valid, review schema design best practices. Follow these rules when creating your schema columns file:
_0-9' or double quote "timestamp type.field type (without a field, there is no time-series data), as in the following example:Valid: a schema with timestamp and field columns.
[
{"name":"time","type":"timestamp"},
{"name":"fsWrite","type":"field"}
]
Not valid: a schema without a field column.
[
{"name":"time","type":"timestamp"},
{"name":"host","type":"tag"}
]
The default field data type is string.
To set the data type of a field column, provide the dataType property and a valid
field data type (string, float, integer, or boolean),
as in the following example:
[
{"name":"time","type":"timestamp"},
{"name":"fsWrite","type":"field","dataType":"float"}
]
Use the InfluxDB UI, influx CLI, or InfluxDB HTTP API to view schema type and schemas for buckets.
To list schemas for a bucket, use the influx bucket-schema list command.
To view schema column definitions and metadata, specify the --json flag.
To list schemas for a bucket, send a request to the InfluxDB HTTP /api/v2/buckets/{BUCKET_ID}/schema/measurements endpoint:
{{% api-endpoint method="get" endpoint="https://{{< influxdb/host >}}/api/v2/buckets/{BUCKET_ID}/schema/measurements" api-ref="/influxdb3/cloud-serverless/api/#operation/getMeasurementSchemas" %}}
Use the influx CLI or the InfluxDB HTTP API to add new columns to an explicit bucket schema.
You can't modify or delete columns in bucket schemas.
View the existing measurement schema and save the columns list to a file.
In your text editor or terminal, append new columns to the list from the previous step.
The following example appends column CO2 to the original sensor.ndjson schema file:
# sensor.ndjson
{{< get-shared-text "bucket-schema/sensor.ndjson" >}}
echo '{"name": "CO2", "type": "field", "dataType": "float"}' >> sensor.ndjson
To update the bucket schema, use the influx bucket-schema update command and specify the columns file with the --columns-file flag.
influx bucket-schema update \
--bucket my_explicit_bucket \
--name sensor \
--columns-file sensor.ndjson
View the existing measurement schema and copy the columns list.
Send a request to the HTTP API /api/v2/buckets/{BUCKET_ID}/schema/measurements/{MEASUREMENT_ID} endpoint.
In the request body, set the columns property to a list of old and new column definitions for the measurement schema--for example, the following request appends the new column CO2 to columns retrieved in the previous step:
{{< api-endpoint method="patch" endpoint="https://{{< influxdb/host >}}/api/v2/buckets/{BUCKET_ID}/schema/measurements/{MEASUREMENT_ID}" api-ref="/influxdb3/cloud-serverless/api/#operation/updateMeasurementSchema" >}}
{
"columns": [
{"name": "time", "type": "timestamp"},
{"name": "sensorId", "type": "tag"},
{"name": "temperature", "type": "field"},
{"name": "humidity", "type": "field", "dataType": "float"},
{"name": "CO2", "type": "field", "dataType": "float"}
]
}
Creating and updating bucket schema requires WRITE permission for the bucket.
If your API token doesn't have WRITE permission for the bucket, InfluxDB returns the following error:
Error: bucket "my_explicit_bucket" not found
Each measurement in a bucket can have one schema. If you attempt to create a schema for an existing measurement, InfluxDB rejects the new schema and returns the following error:
Error: failed to create measurement: 422 Unprocessable Entity
InfluxDB returns an error for the following reasons: