Answers.Body: <p>Hang on, there is a default_value column in the civicrm_custom_field table? I would assume changing that value would actually work....</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-14T10:13:13.193Z
Answers.Text: I'd have assumed that, too, but it does not seem to be the case!
Answers.UserDisplayName: artfulrobot
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-14T12:27:19.283Z
Answers.Text: but that is not fair....
Answers.UserDisplayName: ErikH - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-14T13:41:13.083Z
Answers.Text: I found a fix using [api wrapper](https://civicrm.stackexchange.com/a/16549/35). It's not pretty esp as it now requires different implementations for api3 and api4.
Answers.UserDisplayName: artfulrobot
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-25T08:01:27.620Z
Answers.LastActivityDate: 2019-02-25T08:01:27.620Z
Answers.UserDisplayName: ErikH - CiviCooP
Answers.Body: <p>A possible downside, although unlikely, is an upgrade might do some kind of batch modify on all custom fields that would wipe your default value.</p>
  
  <p>What are you trying to do that can't be done with a hook or trigger?</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-24T20:57:10.957Z
Answers.LastActivityDate: 2019-02-24T20:57:10.957Z
Answers.UserDisplayName: Demerit
Body: <p>When you set a default value for a custom field, it only exists at the form level.  Is there a practical way to enforce them at the database level?  For instance, by altering the SQL table definition?</p>
  
  <p>I understand that a custom field record isn't created under every circumstance, but if I account for that (e.g. another custom field in that group is always populated) is altering the SQL practical?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-04-14T10:15:48.690Z
Comments.Text: Hi, did you ever find a solution to this? [my similar question](https://civicrm.stackexchange.com/questions/16531/how-to-set-a-default-value-for-a-custom-field) has more on this. You mention that custom field records are not always created - do you know why?
Comments.UserDisplayName: artfulrobot
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-04-15T22:30:18.877Z
Comments.Text: @artfulrobot I believe that if you create, e.g, a new contact, but don't populate any of the custom field values in a group, the record isn't created in the corresponding table.  This may only be true via API though, I'm not sure.
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-04-17T06:27:51.210Z
Comments.Text: Yeah. thanks, you're right. (But WHY, Civi, WHY!) I fixed it with an api wrapper - see linked question if interested.
Comments.UserDisplayName: artfulrobot
Tags: <custom-fields><developer><sql>
Title: Custom field default values at database level, not form level?
ThreadText: # Custom field default values at database level, not form level?
  
  (Asked by: username_0 on 2019-02-24)
  
  When you set a default value for a custom field, it only exists at the form level. Is there a practical way to enforce them at the database level? For instance, by altering the SQL table definition?
  
  I understand that a custom field record isn't created under every circumstance, but if I account for that (e.g. another custom field in that group is always populated) is altering the SQL practical?
  
  **Tags:** custom-fields, developer, sql
  
  > **Comments:**
  > **username_1**: Hi, did you ever find a solution to this? [my similar question](https://civicrm.stackexchange.com/questions/16531/how-to-set-a-default-value-for-a-custom-field) has more on this. You mention that custom field records are not always created - do you know why?  
  > **username_0**: @username_1 I believe that if you create, e.g, a new contact, but don't populate any of the custom field values in a group, the record isn't created in the corresponding table.  This may only be true via API though, I'm not sure.  
  > **username_1**: Yeah. thanks, you're right. (But WHY, Civi, WHY!) I fixed it with an api wrapper - see linked question if interested.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2019-02-25. Score: 1
  
  Hang on, there is a default\_value column in the civicrm\_custom\_field table? I would assume changing that value would actually work....
  
  > **Comments:**
  > **username_1**: I'd have assumed that, too, but it does not seem to be the case!  
  > **username_2**: but that is not fair....  
  > **username_1**: I found a fix using [api wrapper](https://civicrm.stackexchange.com/a/16549/35). It's not pretty esp as it now requires different implementations for api3 and api4.  
  
  ---
  
  ### Answer by username_3 on 2019-02-24. Score: 1
  
  A possible downside, although unlikely, is an upgrade might do some kind of batch modify on all custom fields that would wipe your default value.
  
  What are you trying to do that can't be done with a hook or trigger?
  
  
  ---
  
  