OA01 Posted July 8, 2014 Report Share Posted July 8, 2014 I am trying to run a CRON job containing the following commands: mysql_query("update pireps set rawdata='', log='', route='' where submitdate < DATE_SUB(NOW(), INTERVAL 3 MONTH)") or die(mysql_error()); mysql_query("update adminlog set id='', pilotid='', datestamp='', message='' where datestamp < DATE_SUB(NOW(), INTERVAL 1 MONTH)") or die(mysql_error()); mysql_query("update pirepcomments set id='', pirepid='', pilotid='', comment='', postdate='' where postdate < DATE_SUB(NOW(), INTERVAL 3 MONTH)") or die(mysql_error()); The first two lines appear to run OK. However the last line generates the following error: Cannot add or update a child row: a foreign keyconstraint fails (`orangea1_acars`.`pirepcomments`, CONSTRAINT `pirepcomments_ibfk_1` FOREIGN KEY (`pirepid`) REFERENCES `pireps` (`pirepid`) ON DELETE CASCADE ON UPDATE CASCADE) All suggestions welcomed Quote Link to comment Share on other sites More sharing options...
Tom Posted July 8, 2014 Report Share Posted July 8, 2014 Are you actually just updating the fields to '' or have you removed what goes in there? If you're just emptying it, why not DELETE? Quote Link to comment Share on other sites More sharing options...
OA01 Posted July 8, 2014 Author Report Share Posted July 8, 2014 I am trying to delete the contents of those fields. How would I use DELETE? Quote Link to comment Share on other sites More sharing options...
freshJet Posted July 8, 2014 Report Share Posted July 8, 2014 What are you actually trying to do here? Delete all comments older than 3 months? In that case, it would be: DELETE FROM pirepcomments WHERE postdate < DATE_SUB(NOW(), INTERVAL 3 MONTH) Quote Link to comment Share on other sites More sharing options...
Tom Posted July 8, 2014 Report Share Posted July 8, 2014 (And you should probably do the same for the other two queries if that is what you're trying to achieve) Quote Link to comment Share on other sites More sharing options...
OA01 Posted July 8, 2014 Author Report Share Posted July 8, 2014 I'll give it a try, THANKS guys Quote Link to comment Share on other sites More sharing options...
mseiwald Posted July 8, 2014 Report Share Posted July 8, 2014 You definately shouldnt do that with the pireps query or you lose all pireps older than 3 months. 1 Quote Link to comment Share on other sites More sharing options...
Tom Posted July 8, 2014 Report Share Posted July 8, 2014 What are you actually trying to achieve here? Why are you clearing out these particular fields? 1 Quote Link to comment Share on other sites More sharing options...
mseiwald Posted July 8, 2014 Report Share Posted July 8, 2014 its probably related to the out of memory error: http://forum.phpvms.net/topic/8785-out-of-memory/ Quote Link to comment Share on other sites More sharing options...
OA01 Posted July 9, 2014 Author Report Share Posted July 9, 2014 mseiwald is correct. I haven't experienced the problem so far, I'm just trying to keep the DB size to a minimum. Quote Link to comment Share on other sites More sharing options...
Tom Posted July 9, 2014 Report Share Posted July 9, 2014 Right ok, updating is probably the best bet then, don't do it on any id fields though because they have relationships to other tables (plus emptying a small number from each row saves negligible amounts of space - go for the bulky useless stuff) Quote Link to comment Share on other sites More sharing options...
Strider Posted July 10, 2014 Report Share Posted July 10, 2014 If you are worried about an OOM error, then you have two options. First delete some files such as your fleet files and host them else where and link them to your fleet page. Or you could upgrade your hosting package, to increase the space. Quote Link to comment Share on other sites More sharing options...
OA01 Posted July 13, 2014 Author Report Share Posted July 13, 2014 First delete some files such as your fleet files and host them else where and link them to your fleet page. Or you could upgrade your hosting package, to increase the space. Physical space isn't an issue, I have unlimited. I am just performing good housekeeping! The following works a treat. mysql_query("update pireps set rawdata='', log='', route='' where submitdate < DATE_SUB(NOW(), INTERVAL 3 MONTH)") or die(mysql_error()); mysql_query("update adminlog set id='', pilotid='', datestamp='', message='' where datestamp < DATE_SUB(NOW(), INTERVAL 1 MONTH)") or die(mysql_error()); mysql_query("DELETE FROM pirepcomments WHERE postdate < DATE_SUB(NOW(), INTERVAL 2 MONTH)") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Strider Posted July 13, 2014 Report Share Posted July 13, 2014 You should just upgrade your hosting, as deleting pireps is only a temporary solution. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.