Vapor PostgreSQL Error: invalidSQL("ERROR: relation \"pages\" already exists\n")

1k views Asked by At

I am trying to revert a PostgreSQL database with with the Vapor command:

vapor run prepare --revert -y

I get this out put:

Running mist...
Are you sure you want to revert the database?
y/n>yes
Reverting Post
Reverted Post
Removing metadata
Reversion complete

In case you are wondering, I have tried doing this multiple times, so the Post class gets prepared, but the others don't.

This command reverts that tables for all the models, except one (There are four total).

For some reason the 'pages' table will not revert.

And when I try running the app after reverting the database, I get this error:

invalidSQL("ERROR:  relation \"pages\" already exists\n")

Here is the database preparation code for the model:

extension Page: Preparation {
    static func prepare(_ database: Database) throws {
        try database.create("pages", closure: { post in
            post.id()
            post.string("content", length: 10000)
            post.string("name")
            post.string("link")
        })
    }

    static func revert(_ database: Database) throws {
        try database.delete("pages")
    }
}
1

There are 1 answers

0
Caleb Kleveter On BEST ANSWER

I managed to fix this by deleting the old DB:

dropdb `whoami`

Then creating a new one:

createdb `whoami`

Problem solved!