Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Update problem with foreign key
#1

(This post was last modified: 02-07-2021, 12:48 PM by Codinglander.)

Hi community.

During the development of a project I get an error which I cannot solve.

The error message is:
_______________________________________________________________
mysqli_sql_exeption #1452
Cannot add or update a child row: a foreign key constraint fails
____________________________________________________________________

The associated controller function:

PHP Code:
public function update($id)
    {
        $homegame $this->getHomegameOr404($id);

        $post $this->request->getPost();

        unset($post['user_id']);

        $homegame->fill($post);

        if(! $homegame->hasChanged()){
            
            
return redirect()->back()
                             ->with('warning',lang('App.messages.noupdate'))
                             ->withInput();
        }
        
        
if($this->homegame_model->save($homegame)) {

            return redirect()->to("/homegames/show/$id")
                             ->with('info'lang('App.messages.homegame_edited'));
        } else {
            return redirect()->back()
                             ->with('errors'$this->homegame_model->errors())
                             ->with('warning'lang('App.messages.invalid'))
                             ->withInput();
        }
    

The associated tables: (as images)
HOMEGAMES
[Image: table_structure_homegames.png]

USERS
[Image: table_structure_user.png]

How to solve this error ? Any hints ?

Greetings

Kigh...
Reply


Messages In This Thread
[SOLVED] Update problem with foreign key - by Codinglander - 02-07-2021, 03:56 AM
RE: Update problem with foreign key - by paliz - 02-07-2021, 10:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB