Integrity Constraint error - any fix?

Hello!

I’m getting an integrity constraint error followed by a ‘whoops, something went wrong’ message whenever I try to save anything. Does anybody have any sufggestions? Using mysql and php5.6

Many thanks,
Matthew


SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

Are there any more detail about the error in storage/logs/laravel.log, it’d be good to know the specific foreign key. Which version are you running, also was it working and then stopped?

One option is to un-comment the Event::listen code at the bottom of app/Http/routes.php, this will log all queries to laravel.log which should show the one that’s failing.

Hello!

Running the latest version, not from github. I have had some installation issues that you helped me with - thanks again, by the way!

I’ll post the a log excerpt, sanitised, below. I haven’t gone through everything so this won’t be a complete list of keys. What I could do is try to drop all the tables in mysqladmin with the check left on and see what doesn’t get dropped?

2015-07-08 13:11:47] production.ERROR: Illuminate\Database\QueryException [23000] : //laravel/framework/src/Illuminate/Database/Connection.php [Line 624] => SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (carbonba_ninjadb.accounts, CONSTRAINTaccounts_industry_id_foreignFOREIGN KEY (industry_id) REFERENCESindustries(id)) (SQL: updateaccountssettimezone_id= 103,date_format_id= 3,datetime_format_id= 5,currency_id= 12,updated_at= 2015-07-08 13:11:47,name= ,address1= ,address2= ,city= ,state= ,postal_code= 4034,country_id= 36,industry_id= 43,size_id= 1,work_phone= xxx,work_email= xxx,vat_number= ABN: ,id_number= whereid` = 1)
{“context”:“PHP”,“user_id”:“1”,“user_name”:"",“url”:“http:///company/details”,“user_agent”:“Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0”,“ip”:"",“count”:1}

The industry_id is 43, the max should be 31. I think this is an issue with the latest code in GitHub. We’ve enabled using the setup screen after the database has been initialized but it’s causing the constant seeder to be run twice.

I’ll try to check in a fix later today, until then you need to skip running “php artisan migrate --seed” when setting up the site.

That would explain why some items are appearing twice in the list as well :slight_smile: I haven’t got any data in there yet, I could happily blow it away and start from scratch.