Reputation: 1688
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.
Upvotes: 2
Views: 652
Reputation: 11494
You need to create the database from the terminal before your Vapor app can connect to it:
createdb trialService
Upvotes: 4