Reputation: 2678
I'm trying to add a new required field in a Fluent migration. Just like this example from the docs:
database.schema("planets")
.field("name", .string, .required)
.update()
But when I run migrate
I get an error saying that column "name" of relation "planets" contains null values.
Is there a way to set the default value for adding a required field to a table with pre-existing records?
Upvotes: 0
Views: 708
Reputation: 5565
You can do something like
database.schema("planets")
.field("name", .string, .required, .sql(.default("Unknown"))
.update()
Upvotes: 2