<p>This is the mySQL query I have used to update a lightswitch field in the database.</p>

<pre><code>UPDATE `table` SET `field_name` = replace(field_name,'original content', 'updated content')
</code></pre>

<p>for example:</p>

<pre><code>UPDATE `craft_content` SET `field_imageLightbox` = replace(field_imageLightbox,'0', '1')
</code></pre>

CC BY-SA 4.0
2019-03-08T16:40:26.103Z
2019-03-08T16:40:26.103Z
Terry Upton
<p>For entries previously created, the lightswitch field will not be <em>on</em> even if you specified that as a field option. However, new entries should respect that field setting.</p>

<p>Are new entries not honoring your field settings?</p>

CC BY-SA 3.0
2017-02-21T20:52:42.253Z
I see, I did not expect that behaviour, you are correct in that is what I am experiencing. Presumably I'd have to write a plugin to re-save entries with the 'on' value set.
Adam Menczykowski
CC BY-SA 3.0
2017-02-21T21:57:46.433Z
@AdamMenczykowski If you're comfortable with SQL, you could update the value of light switch field in the content table for entry elements in the desired section. Not super simple but should be quick and painless if you can write the SQL with a couple criteria in the where clause.
Selvin Ortiz
CC BY-SA 3.0
2018-01-04T12:04:56.847Z
Could anyone provide example code on how to write SQL query code to enable all lightswitches on existing entries please?
Adam Menczykowski
CC BY-SA 4.0
2018-08-22T16:34:47.530Z
I too would like example sql code
CreateSean
CC BY-SA 4.0
2019-06-05T15:25:40.737Z
Is there no way of selecting all entries in a structure and re-saving all at once?
mateostabio
CC BY-SA 3.0
2017-02-21T17:55:36.713Z
2017-02-21T17:55:36.713Z
Selvin Ortiz
<p>I'm creating a new lightswitch field and adding it to an entry type in a section which already has dozens of entries. I want the lightswitch to be default set to 'on'.</p>

<p>When I save the entry type with the lightswitch field added to a tab, then inspect an entry in that section, the new lightswitch field is set to 'off'. Is this a bug?</p>

<lightswitch><default>
Can the Lightswitch field have a default 'on' setting?
# Can the Lightswitch field have a default 'on' setting?

(Asked by: username_0 on 2017-02-21)

I'm creating a new lightswitch field and adding it to an entry type in a section which already has dozens of entries. I want the lightswitch to be default set to 'on'.

When I save the entry type with the lightswitch field added to a tab, then inspect an entry in that section, the new lightswitch field is set to 'off'. Is this a bug?

**Tags:** lightswitch, default

---

## 2 answers

### Answer by username_2 on 2017-02-21. Score: 7 | Accepted answer

For entries previously created, the lightswitch field will not be *on* even if you specified that as a field option. However, new entries should respect that field setting.

Are new entries not honoring your field settings?

> **Comments:**
> **username_0**: I see, I did not expect that behaviour, you are correct in that is what I am experiencing. Presumably I'd have to write a plugin to re-save entries with the 'on' value set.  
> **username_2**: @AdamMenczykowski If you're comfortable with SQL, you could update the value of light switch field in the content table for entry elements in the desired section. Not super simple but should be quick and painless if you can write the SQL with a couple criteria in the where clause.  
> **username_0**: Could anyone provide example code on how to write SQL query code to enable all lightswitches on existing entries please?  
> **username_3**: I too would like example sql code  
> **username_4**: Is there no way of selecting all entries in a structure and re-saving all at once?  

---

### Answer by username_1 on 2019-03-08. Score: 1

This is the mySQL query I have used to update a lightswitch field in the database.
UPDATE `table` SET `field_name` = replace(field_name,'original content', 'updated content')

for example:
UPDATE `craft_content` SET `field_imageLightbox` = replace(field_imageLightbox,'0', '1')


---

