partkeepr / PartKeepr

Open Source Inventory Management
http://www.partkeepr.org
GNU General Public License v3.0
1.4k stars 403 forks source link

Add part to project error #200

Closed szechyjs closed 12 years ago

szechyjs commented 12 years ago

This may be related to my database being migrated from a build from September. I have created a new project, it saves fine provided I don't have any parts added, however once I add a part and click save I get the following error. The parts I'm adding existed in my September version of the database, the project is newly created.

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`partkeepr`.`ProjectPart`, CONSTRAINT `FK_B0B19336166D1F9C` FOREIGN KEY (`project_id`) REFERENCES `Part` (`id`))

Exception
==================================
PDOException

Backtrace
==================================
PDOException

Request
==================================
{"method":"PUT","headers":{"session":"pooutjqvnpo0bh7jub98s19vg6"},"jsonData":{"id":1,"name":"Kegboard","description":"Arduino shield for the kegbot project.","user_id":0,"parts":[{"quantity":1,"id":0,"project_id":0,"part_id":15,"part_name":"DS1820","remarks":"Digital Thermometer","partkeepr.project_id":1}],"attachments":[]}}

Response
==================================
{"status":"systemerror","success":false,"exception":{"message":"SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`partkeepr`.`ProjectPart`, CONSTRAINT `FK_B0B19336166D1F9C` FOREIGN KEY (`project_id`) REFERENCES `Part` (`id`))","exception":"PDOException","backtrace":"#0 \/usr\/share\/php\/Doctrine\/DBAL\/Statement.php(131): PDOStatement->execute(NULL)\n#1 \/usr\/share\/php\/Doctrine\/ORM\/Persisters\/BasicEntityPersister.php(239): Doctrine\\DBAL\\Statement->execute()\n#2 \/usr\/share\/php\/Doctrine\/ORM\/UnitOfWork.php(896): Doctrine\\ORM\\Persisters\\BasicEntityPersister->executeInserts()\n#3 \/usr\/share\/php\/Doctrine\/ORM\/UnitOfWork.php(304): Doctrine\\ORM\\UnitOfWork->executeInserts(Object(Doctrine\\ORM\\Mapping\\ClassMetadata))\n#4 \/usr\/share\/php\/Doctrine\/ORM\/EntityManager.php(355): Doctrine\\ORM\\UnitOfWork->commit(NULL)\n#5 \/var\/www\/parts\/src\/backend\/de\/RaumZeitLabor\/PartKeepr\/Project\/ProjectService.php(47): Doctrine\\ORM\\EntityManager->flush()\n#6 \/var\/www\/parts\/src\/backend\/de\/RaumZeitLabor\/PartKeepr\/Service\/ServiceManager.php(80): de\\RaumZeitLabor\\PartKeepr\\Project\\ProjectService->update()\n#7 \/var\/www\/parts\/frontend\/rest.php(55): de\\RaumZeitLabor\\PartKeepr\\Service\\ServiceManager::call()\n#8 {main}"},"timing":0.02181601524353}

Server Configuration
==================================
doctrine_orm_version: 2.2.2
doctrine_dbal_version: 2.2.2
doctrine_common_version: 2.2.2
php_version: 5.3.2-1ubuntu4.11
maxUploadSize: 2097152
availableImageFormats: 3FR,A,AI,ART,ARW,AVI,AVS,B,BGR,BMP,BMP2,BMP3,BRF,BRG,C,CAL,CALS,CAPTION,CIN,CIP,CLIP,CMYK,CMYKA,CR2,CRW,CUR,CUT,DCM,DCR,DCX,DDS,DFONT,DJVU,DNG,DOT,DPX,EPDF,EPI,EPS,EPS2,EPS3,EPSF,EPSI,EPT,EPT2,EPT3,ERF,EXR,FAX,FITS,FRACTAL,FTS,G,G3,GBR,GIF,GIF87,GRADIENT,GRAY,GRB,GROUP4,HALD,HISTOGRAM,HRZ,HTM,HTML,ICB,ICO,ICON,INFO,INLINE,IPL,ISOBRL,JNG,JP2,JPC,JPEG,JPG,JPX,K,K25,KDC,LABEL,M,M2V,M4V,MAP,MAT,MATTE,MIFF,MNG,MONO,MOV,MP4,MPC,MPEG,MPG,MRW,MSL,MSVG,MTV,MVG,NEF,NULL,O,ORF,OTB,OTF,PAL,PALM,PAM,PATTERN,PBM,PCD,PCDS,PCL,PCT,PCX,PDB,PDF,PDFA,PEF,PFA,PFB,PFM,PGM,PGX,PICON,PICT,PIX,PJPEG,PLASMA,PNG,PNG24,PNG32,PNG8,PNM,PPM,PREVIEW,PS,PS2,PS3,PSD,PTIF,PWP,R,RADIAL-GRADIENT,RAF,RAS,RBG,RGB,RGBA,RGBO,RLA,RLE,SCR,SCT,SFW,SGI,SHTML,SR2,SRF,STEGANO,SUN,SVG,SVGZ,TEXT,TGA,THUMBNAIL,TIFF,TIFF64,TILE,TIM,TTC,TTF,TXT,UBRL,UIL,UYVY,VDA,VICAR,VID,VIFF,VST,WBMP,WMF,WMV,WMZ,WPG,X,X3F,XBM,XC,XCF,XPM,XPS,XV,XWD,Y,YCbCr,YCbCrA,YUV
Drachenkaetzchen commented 12 years ago

Can you send a dump of your database? I can't reproduce it, and would need to look into the database.

szechyjs commented 12 years ago

http://pastebin.com/ckJbpbAR

Drachenkaetzchen commented 12 years ago

This is actually a bug in Doctrine2 - see http://www.doctrine-project.org/jira/browse/DDC-1586

One fix is to change the foreign key inside the ProjectPart table to reference the correct target. It is pretty easy using phpMyadmin.

Drachenkaetzchen commented 12 years ago

SQL Statement to fix this manually (backup your DB first):

ALTER TABLE ProjectPart DROP FOREIGN KEY FK_B0B19336166D1F9C , ADD FOREIGN KEY ( project_id ) REFERENCES partkeepr.Project ( id ) ON DELETE RESTRICT ON UPDATE RESTRICT ;

szechyjs commented 12 years ago

Thanks! That resolved the issue.

On Sun, May 27, 2012 at 5:48 AM, timoahummel < reply@reply.github.com

wrote:

SQL Statement to fix this manually (backup your DB first):

ALTER TABLE ProjectPart DROP FOREIGN KEY FK_B0B19336166D1F9C , ADD FOREIGN KEY ( project_id ) REFERENCES partkeepr.Project ( id ) ON DELETE RESTRICT ON UPDATE RESTRICT ;


Reply to this email directly or view it on GitHub: https://github.com/partkeepr/PartKeepr/issues/200#issuecomment-5952486

Drachenkaetzchen commented 12 years ago

This is actually a duplicate of #129 - I'll close this, as the other issue contains more information.