蒸气 Swift 错误 "Reference to member 'sqlite' cannot be resolved without a contextual type"

Vapor Swift Error "Reference to member 'sqlite' cannot be resolved without a contextual type"

在全新安装 Vapor(来自 homebrew)时,我调用:

我得到的错误是:

[1/3] Compiling App configure.swift
/Users/josh/Applications/Xcode/Projects/Bridge/Sources/App/configure.swift:31:49: error: reference to member 'sqlite' cannot be resolved without a contextual type
    migrations.add(model: Todo.self, database: .sqlite)
                                               ~^~~~~~
[2/3] Compiling App app.swift

版本号:

如果您能提供解决此错误的帮助,我们将不胜感激!如果我可以提供更多信息,请告诉我。谢谢!

是的,Vapor 3 在 Swift 5.2
上遇到编译问题 https://forums.swift.org/t/vapor-3-swift-5-2-regression/34764

migrations.add(model: Todo.self, database: .sqlite)

以上代码在 Swift 5.1 中编译良好,现在将导致以下错误:

Reference to member 'sqlite' cannot be resolved without a contextual type

这可以通过使用显式类型而不是前导点语法来解决:

migrations.add(model: Todo.self, database: DatabaseIdentifier<SQLiteDatabase>.sqlite)

ToDoclass中添加typelias,当你使用Swift5.2

final class Todo: SQLiteModel {

    typealias Database = SQLiteDatabase

    ....
}