Skip to content
Advertisement

Error Code: 3813. Column check constraint ‘customer_details_chk_2’ references other column

Advertisement

Answer

MySQL only started supporting check constraints in MySQL 8.0.16 — released in April 2019.

Prior to that, the syntax was allowed (although perhaps with limitations), but nothing happened.

What is happening in your code is that you have:

These are inline check constraints. That means they are part of the column definition. You can fix this just by adding commas:

I like to make my constraints obvious, so I would put them after the columns and give them names:

Here is a db<>fiddle.

Note: Don’t use char() for column types — it pads the string with spaces. Use varchar().

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement