2

I'm writing a web service in Swift using Vapor 3. I'm using FluentPostgreSQL for data persistence. I have a user model which conforms to both PostgreSQLModel, PostgreSQLMigration. The app builds correctly. However, when I run the app, I am getting the following error.

Fatal error: Error raised at top level: ⚠️ PostgreSQL Error: database "trialService" does not exist
- id: PostgreSQLError.server.fatal.InitPostgres

This is how my configure.swift looks like.

try services.register(FluentPostgreSQLProvider())

let configPSQL = PostgreSQLDatabaseConfig(hostname: "localhost", username: "imthath", database: "trialService")
let psql = PostgreSQLDatabase(config: configPSQL)

var databases = DatabasesConfig()
databases.add(database: sqlite, as: .sqlite)
databases.add(database: psql, as: .psql)
services.register(databases)

As you can see I was earlier using SQLite and now I am trying to use PostgreSQL for some models including User. I did not get any error when I was only SQLite.

imthath
  • 1,353
  • 1
  • 13
  • 35
  • As an alternative, a tool such as `Postico` can be used to create a database. And then run `vapor run migrate` in terminal. – iCodes Apr 21 '21 at 05:19

1 Answers1

4

You need to create the database from the terminal before your Vapor app can connect to it:

createdb trialService
Caleb Kleveter
  • 11,170
  • 8
  • 62
  • 92