Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I'm updating our dotnet core project to use PostgreSQL on the backend instead of Microsoft SQL Server and hit a situation with two tables that use a GUID as the data type.

ERROR

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Property CommentID on type is a database-generated uuid, which requires the PostgreSQL uuid-ossp extension. Add .HasPostgresExtension("uuid-ossp") to your context's OnModelCreating.

After a little googling I then realized I have to enable the uuid extension (not sure if this can be automated somehow) and then generated a uuid in pgAdmin successfully.

CREATE EXTENSION "uuid-ossp";
SELECT uuid_generate_v4();

Unfortunately my dotnet project is still complaining with the same error tho. I see in the error it says to add .HasPostgresExtension("uuid-ossp") to OnModelCreating and I've tried in several spots but can't seem to figure out where specifically it should be added.

share|improve this question
    
HasPostgresExtension() needs to be placed in your context's OnModelCreating, as the error says. If it doesn't please post the relevant portions of your context. Note that you must be using at least version 1.0.0-rc3-ci-39 from the Npgsql unstable feed for this to work. – Shay Rojansky Jun 2 at 6:25

As per Shay's instruction - After updating to the latest version of Npgsql, the uuid extension error is now gone. Here's a snippet of what the OnModelCreating looks like for others trying this out:

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        builder.HasPostgresExtension("uuid-ossp");
    }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.