fix(add): fixed #199, foreign key constraint failed

This commit is contained in:
2025-12-20 15:22:45 -05:00
parent ede8d996e2
commit 1184f9bf48
2 changed files with 13 additions and 11 deletions

View File

@@ -33,11 +33,7 @@ class BrickMinifigure(RebrickableMinifigure):
)
)
if not refresh:
# Insert into database
self.insert(commit=False)
# Load the inventory
# Load the inventory (needed to count parts for rebrickable record)
if not BrickPartList.download(
socket,
self.brickset,
@@ -46,9 +42,14 @@ class BrickMinifigure(RebrickableMinifigure):
):
return False
# Insert the rebrickable set into database (after counting parts)
# Insert the rebrickable minifigure into database first (parent record)
# This must happen before inserting into bricktracker_minifigures due to FK constraint
self.insert_rebrickable()
if not refresh:
# Insert into bricktracker_minifigures database (child record)
self.insert(commit=False)
except Exception as e:
socket.fail(
message='Error while importing minifigure {figure} from {set}: {error}'.format( # noqa: E501

View File

@@ -62,13 +62,14 @@ class BrickPart(RebrickablePart):
)
)
if not refresh:
# Insert into database
self.insert(commit=False)
# Insert the rebrickable set into database
# Insert the rebrickable part into database first (parent record)
# This must happen before inserting into bricktracker_parts due to FK constraint
self.insert_rebrickable()
if not refresh:
# Insert into bricktracker_parts database (child record)
self.insert(commit=False)
except Exception as e:
socket.fail(
message='Error while importing part {part} from {kind} {identifier}: {error}'.format( # noqa: E501