如何在流式迁移中为非可选字段添加默认值?我目前有这个错误:
⚠️ PostgreSQL Error: column "firstName" contains null values
我唯一的选择是
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)
编辑:感谢蒂姆的回答,解决方案是:
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("")))
}
}