Skip to content

Data and tenancy

Option Default Purpose
$uuidField 'uuid' column of the public BINARY(16) UUID of every Anvil model
$internalFields ['id', 'tenant_id'] columns that never leave the server (JSON of entities, API)
$multiTenancy true models are tenant scoped unless they opt out ($tenantScoped = false)
$tenantField 'tenant_id' tenant column of scoped models

Every Anvil model has an internal integer key and a public UUID, see Data rules. Change $uuidField and $tenantField only before the first migration: they are column names in every table. Add columns to $internalFields that must never appear in JSON, e.g. ['id', 'tenant_id', 'legacy_id']; models can add their own with $internal.

With $multiTenancy = true (default):

  • every Anvil model is restricted to the current tenant,
  • panels select the tenant of the user (anvil-tenant filter) and offer the tenant switcher,
  • roles, workflows, documents, files and notifications are per tenant.

Applications with a single organisation can switch it off:

public bool $multiTenancy = false;

Switching with existing data needs care, see Tenancy. Single panels can opt out with Panel::hasTenancy(), see Panels → Tenants.