Error
Error Code: 3104

MySQL Error 3104: FK on Generated Column

📦 MySQL
📋

Description

This error occurs when you attempt to define a foreign key constraint on a generated column in MySQL, and simultaneously include an `ON DELETE` or `ON UPDATE` clause. MySQL restricts the use of these clauses for foreign keys that reference generated columns. It typically arises during `CREATE TABLE` or `ALTER TABLE` operations.
💬

Error Message

Cannot define foreign key with %s clause on a generated column.
🔍

Known Causes

3 known causes
⚠️
Direct FK Constraint
Attempting to define a foreign key on a generated column with `ON DELETE` or `ON UPDATE` clauses directly within a `CREATE TABLE` or `ALTER TABLE` statement.
⚠️
Misidentified Column Type
Unintentionally applying a foreign key with action clauses to a column that is a generated column, due to an oversight in schema understanding or design.
⚠️
Tool-Generated DDL Error
Database management tools or ORMs generating incorrect DDL statements that include forbidden foreign key clauses on generated columns.
🛠️

Solutions

Coming Soon

Detailed step-by-step solutions for this error are being prepared. In the meantime, try these general troubleshooting tips:

General Troubleshooting Tips

  • Check the error message carefully for specific details
  • Review recent changes that might have caused the error
  • Search for the exact error code in the official documentation
  • Check log files for additional context
  • Try restarting the application or service
🔗

Related Errors

5 related errors