How do I add a default value for a non-optional field in a fluent migration? I currently have this error:
⚠️ PostgreSQL Error: column "firstName" contains null values
my only options are
public func field<T>(for key: KeyPath<Self.Model, T>, isIdentifier: Bool? = nil)
public func field<T>(for key: KeyPath<Self.Model, T>, type: Self.Model.Database.SchemaFieldType)
EDIT: Thanks to Tim's answer, the solution is:
static func prepare(on conn: PostgreSQLConnection) -> Future<Void> {
return Database.update(User.self, on: conn) { builder in
builder.field(for: \User.firstName, type: .text, .default(.literal("")))
}
}