diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,6 @@
 # CHANGELOG
 
-## 3.8.0
+## 3.8.1
 ### Changed
 * Compatibility with ghc-8.8.3
 
diff --git a/postgresql-query.cabal b/postgresql-query.cabal
--- a/postgresql-query.cabal
+++ b/postgresql-query.cabal
@@ -1,5 +1,5 @@
 name:                postgresql-query
-version:             3.8.0
+version:             3.8.1
 
 synopsis: Sql interpolating quasiquote plus some kind of primitive ORM
           using it
diff --git a/src/Database/PostgreSQL/Query/Entity/Functions.hs b/src/Database/PostgreSQL/Query/Entity/Functions.hs
--- a/src/Database/PostgreSQL/Query/Entity/Functions.hs
+++ b/src/Database/PostgreSQL/Query/Entity/Functions.hs
@@ -27,6 +27,7 @@
 import Database.PostgreSQL.Simple.FromField
 import Database.PostgreSQL.Simple.ToField
 
+import qualified Control.Monad.Fail as F
 import qualified Data.List as L
 import qualified Data.List.NonEmpty as NL
 
@@ -35,7 +36,7 @@
 pgInsertEntity
   :: forall a m
    . ( MonadPostgres m, MonadLogger m, Entity a
-     , ToRow a, FromField (EntityId a) )
+     , ToRow a, FromField (EntityId a), F.MonadFail m )
   => a
   -> m (EntityId a)
 pgInsertEntity a = do
diff --git a/src/Database/PostgreSQL/Query/TH/Entity.hs b/src/Database/PostgreSQL/Query/TH/Entity.hs
--- a/src/Database/PostgreSQL/Query/TH/Entity.hs
+++ b/src/Database/PostgreSQL/Query/TH/Entity.hs
@@ -87,12 +87,18 @@
       [a] -> return a
       x -> fail $ "expected exactly 1 data constructor, but " ++ show (length x) ++ " got"
     econt <- [t|Entity $(conT tname)|]
+    eidcont <- [t|EntityId $(conT tname)|]
     ConT entityIdName <- [t|EntityId|]
     let tnames = nameBase tname
         idname = tnames ++ "Id"
         unidname = "get" ++ idname
         idtype = ConT (eoIdType opts)
-#if MIN_VERSION_template_haskell(2,12,0)
+#if MIN_VERSION_template_haskell(2,15,0)
+        idcon = RecC (mkName idname)
+                [(mkName unidname, Bang NoSourceUnpackedness NoSourceStrictness, idtype)]
+        iddec = NewtypeInstD [] Nothing eidcont Nothing
+                idcon [DerivClause Nothing (map ConT $ eoDeriveClasses opts)]
+#elif MIN_VERSION_template_haskell(2,12,0)
         idcon = RecC (mkName idname)
                 [(mkName unidname, Bang NoSourceUnpackedness NoSourceStrictness, idtype)]
         iddec = NewtypeInstD [] entityIdName [ConT tname] Nothing
