A generated column expression uses a disallowed or nondeterministic function, so MySQL rejects the CREATE or ALTER TABLE statement.
ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED appears when a generated column references a nondeterministic or blocked function like RAND() or NOW(). Replace the forbidden function with a deterministic alternative and rerun the CREATE or ALTER TABLE statement to fix the error.
ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
MySQL raises error 3102 when a generated column expression contains a function that is nondeterministic, depends on connection context, or is explicitly disallowed. Examples include RAND(), NOW(), UUID(), or subqueries. The server rejects the CREATE or ALTER TABLE statement to protect data consistency and replication safety.
The restriction was introduced in MySQL 5.7.6 alongside generated columns. By blocking unsafe functions, MySQL ensures that every replica computes the same value for a generated column, preventing drift in statement based replication and guaranteeing repeatable reads.
The error occurs whenever a generated column references a function that MySQL marks as non-deterministic or non-pure. Functions that read the current time, random numbers, user variables, or system status produce different results per call, violating determinism. MySQL therefore flags the definition as unsafe.
The error also appears if the expression uses functions needing the SUPER privilege when invoked in stored programs, because generated columns run with the definer's privileges and must stay safe for every user.
Identify the forbidden function in the generated column expression. Replace it with a deterministic equivalent or compute the value in application code. For current timestamps, store the value in a regular column with DEFAULT CURRENT_TIMESTAMP and reference that column in the generated expression instead.
After modifying the expression, rerun the CREATE TABLE or ALTER TABLE statement. The table will now be created or altered without raising error 3102.
Using RAND() to create a random hash fails. Generate the random value in the application and write it to a base column, then let the generated column reference that stored value.
Including NOW() or CURRENT_TIMESTAMP in a date math expression fails. Store the insert timestamp in a normal column with a default, then derive the generated column from that stored timestamp.
Keep generated column expressions deterministic and based only on columns of the same row. Avoid calling functions that read external state. Prefer pure string, arithmetic, and JSON functions that MySQL marks as deterministic.
Create unit tests or migration checks that attempt to create tables in a staging database so the error is caught during CI rather than in production.
Error 3105 ER_GENERATED_COLUMN_REF_AUTO_INC occurs when a generated column references an AUTO_INCREMENT column in an invalid context. Ensure the reference is allowed or move logic to the application. Error 1293 HY000 sets @@sql_mode restrictions that also affect determinism checks.
Functions like RAND(), UUID(), and NOW() return different results each call, so MySQL blocks them in generated columns.
Functions that rely on user, connection, or server state such as CURRENT_USER() are disallowed.
Generated columns cannot execute subqueries or GROUP BY operations because they may change per row or execution.
Raised when a generated column references an AUTO_INCREMENT column in a disallowed way. Remove the reference or convert to STORED.
Appears when trying to modify a generated column with UPDATE. Generated columns are read-only and must be altered via DDL.
Certain sql_mode settings influence determinism checks and can surface during generated column creation.
No. NOW() is nondeterministic. Store the timestamp in a normal column with DEFAULT CURRENT_TIMESTAMP and reference that column instead.
Deterministic functions that depend only on their arguments, such as CONCAT, JSON_EXTRACT, ABS, or arithmetic operators, are allowed.
Yes. Both STORED and VIRTUAL generated columns must use deterministic functions.
Galaxy's SQL editor highlights nondeterministic functions in generated column expressions and its AI copilot suggests compliant alternatives before you run the query, avoiding runtime failures.