Getting 'relation "schemaversions" does not exist error'

763 views Asked by At

Im trying to use the example code from dbup converted to postgres.

Below is the code.

using System;
using System.Linq;
using System.Reflection;
using DbUp;

namespace GeoServerDbManager
{
    //"Host = 1.1.1.1; User Id = postgres; Password = postgres; Database = osmdev; Port = 5432"
    class Program
    {
        static int Main(string[] args)
        {
            var connectionString =
                args.FirstOrDefault()
                ?? "Host = 1.1.1.1; User Id = postgres; Password = postgres; Database = osmdev; Port = 5432";
            EnsureDatabase.For.PostgresqlDatabase(connectionString);
            var upgrader =
                DeployChanges.To
                    .PostgresqlDatabase(connectionString)
                    .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
                    .LogToConsole()
                    .Build();

            var result = upgrader.PerformUpgrade();

            if (!result.Successful)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(result.Error);
                Console.ResetColor();
#if DEBUG
                Console.ReadLine();
#endif
                return -1;
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Success!");
            Console.ResetColor();
            return 0;
        }
    }
}

The database doesnt exist when I run this. I keep getting the error:

Script block number: 0; Message: 42P01: relation "schemaversions" does not exist
Npgsql.PostgresException (0x80004005): 42P01: relation "schemaversions" does not exist

The tables do get created and so does the schemaversions table but the schemaversions table is empty at the end of the script.

1

There are 1 answers

0
Mike Bovenlander On BEST ANSWER

I know this is an old question but today I ran into the same problem and since there is no answer yet I'm answering for future reference:

I found that DbUp is trying to create a "schemaversions" but there is no default schema set. This results in the error:

Getting 'relation "schemaversions" does not exist error'

Setting the default schema fixed the problem for me:

builder.JournalToPostgresqlTable("SCHEMA_NAME", "schemaversions")