tenhittender
tenhittender

Reputation: 479

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

On a fresh install of Vapor (from homebrew) I call:

The error I get is:

[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

Version Numbers:

Any help figuring out how to solve this error is appreciated! Let me know if I can provide any more information. Thanks!

Upvotes: 6

Views: 1467

Answers (2)

mistdon
mistdon

Reputation: 1883

Add typelias in ToDo class, when you use Swift 5.2

final class Todo: SQLiteModel {

    typealias Database = SQLiteDatabase

    ....
}

Upvotes: 12

imike
imike

Reputation: 5656

Yeah Vapor 3 experience compilation problems on Swift 5.2
https://forums.swift.org/t/vapor-3-swift-5-2-regression/34764

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

The above code, which compiles fine in Swift 5.1, will now result in the following error:

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

This can be fixed by using an explicit type instead of leading-dot syntax:

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

Upvotes: 12

Related Questions