You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The migration fails with table a_backup has no column named id, because the generated SQL still includes the non-existing id-column although we have a custom primary key:
The problem lies in thesetwo lines, as they prepend the id column regardless of its actual existence.
Patch
This following patch works for me, but I don't really understand the ReferenceDef type, but if I have got it correctly and there are no other cases to consider, I'll prepare a pull request + test case.
diff --git a/persistent-sqlite/Database/Persist/Sqlite.hs b/persistent-sqlite/Database/Persist/Sqlite.hs
index ab72ec7..d811578 100644
--- a/persistent-sqlite/Database/Persist/Sqlite.hs+++ b/persistent-sqlite/Database/Persist/Sqlite.hs@@ -375,12 +375,11 @@ getCopyTable allDefs getter def = do
let oldCols = map DBName $ filter (/= "id") oldCols' -- need to update for table id attribute ?
let newCols = filter (not . safeToRemove def) $ map cName cols
let common = filter (`elem` oldCols) newCols
- let id_ = fieldDB (entityId def)
return [ (False, tmpSql)
- , (False, copyToTemp $ id_ : common)+ , (False, copyToTemp $ addIdCol common)
, (common /= filter (not . safeToRemove def) oldCols, dropOld)
, (False, newSql)
- , (False, copyToFinal $ id_ : newCols)+ , (False, copyToFinal $ addIdCol newCols)
, (False, dropTmp)
]
where
@@ -418,6 +417,10 @@ getCopyTable allDefs getter def = do
, " FROM "
, escape tableTmp
]
+ addIdCol = let id_ = entityId def+ in case fieldReference id_ of+ CompositeRef _ -> id+ _ -> (fieldDB id_ :)
mkCreateTable :: Bool -> EntityDef -> ([Column], [UniqueDef]) -> Text
mkCreateTable isTemp entity (cols, uniqs) =
The text was updated successfully, but these errors were encountered:
Description
Let's say we have this model definition
and change it to
The migration fails with
table a_backup has no column named id
, because the generated SQL still includes the non-existingid
-column although we have a custom primary key:Identified problem
The problem lies in these two lines, as they prepend the
id
column regardless of its actual existence.Patch
This following patch works for me, but I don't really understand the
ReferenceDef
type, but if I have got it correctly and there are no other cases to consider, I'll prepare a pull request + test case.The text was updated successfully, but these errors were encountered: