Search code examples
swiftvapor

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


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

  • vapor new Bridge -> success
  • vapor xcode -> success
  • y (asks if I want to open the project in Xcode) -> opens Xcode project
  • vapor --version -> 3.1.10
  • vapor build -> fails

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:

  • macOS: 10.15.3 (19D76)
  • Xcode: 11.4 (11E146)
  • Vapor: 3.1.10
  • Swift: 5.2

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


Solution

  • Add typelias in ToDo class, when you use Swift 5.2

    final class Todo: SQLiteModel {
    
        typealias Database = SQLiteDatabase
    
        ....
    }