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:
感谢Tim的回答,解决方案是: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("")))
}
}
如果有人到达这里并试图在蒸气4中进行操作:
func prepare(on database: Database) -> EventLoopFuture<Void> {
database.schema("event")
.field("is_private", .bool, .sql(.default(false)))
.update()
}
the是您尚未看到的另一个选择:
static func prepare(on connection: PostgreSQLConnection) -> Future<Void> {
return Database.update(Event.self, on: connection) { builder in
builder.field(for: \Event.isPrivate, type: .boolean, .default(.literal(.boolean(.false))))
}
}