A
A
Andre972021-03-09 12:52:57
Laravel
Andre97, 2021-03-09 12:52:57

How to specify the default field value in Laravel migration, but write another one for existing values?

Good afternoon. We need to add a field to the table. Is it possible to somehow specify in the migration that the default value is false, but so that already existing records are set to true ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2021-03-09
@Andre97

Just right in the migration after creating the column with a separate query, update the value in the existing records.

J
jazzus, 2021-03-09
@jazzus

In different migrations

$table->boolean('active')->default(true);
$table->boolean('active')->default(false)->change();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question