Database error, not null Violation, I am passing all values, where am I missing?

Asked

Viewed 420 times

0

After completing the form and submitting, returns the following array:

array(
       'User' => array(
               'password' => '*****',
               'nome' => 'Engenharia',
               'username' => '[email protected]',
               'confirm_password' => '123',
       ),
       'Endereco' => array(
               (int) 0 => array(
                    'cidade_id' => '3091',
                          'cep' => '96032012',
                          'rua' => 'Conde de porto alegre',
                          'numero' => '420',
                          'bairro' => 'Porto',
                          'complemento' => 'Empresa'
                  )
        ),
        'UserGroup' => array(
                 'group_id' => '2',
                 'nome' => 'Cliente'
         )
)

Then I receive the following message:

Database Error Error: SQLSTATE[23502]: Not null Violation: 7 ERROR: null value in column "name" violates not-null Constraint. DETAIL: Failing Row contains (87, 2, 180, null).
Notice: If you want to customize this error message, create app/View/Errors/pdo_error.ctp

But I don’t understand where he’s getting this nome == null, because I’m passing the name of User and I’m passing the name of UserGroup also, where I may be missing?

  • It seems that the error is not here. Something else may be occurring and causing the error.

  • Yeah, I’ve checked enough, but I’m not finding the problem :|

  • I’m saving with $this->User->saveAssociated($this->request->data);

  • 1

    Is it possible for you to temporarily remove this Constraint from the seat to see what will be recorded? Maybe seeing what was recorded you’ll find out where this error.

  • True, I’ll take a look!

  • I took the Constraint off the field nome table UserGroup and saved normally, but with null value of course. Does it conflict with the two tables with fields of the same name ? User => 'nome' and the UserGroup => 'nome'

  • This array is exactly before save? Referring to conflict named after two equal tables, it will depend on your Model...

  • Yes he is before save, I don’t know what happened, but I decided to remove this field from the table of the bank and use the other table that did the same function. Just did one more relationship in the table and searched the values of this new table.

Show 3 more comments

1 answer

0


My solution:

After completing the form and submitting, returns the following array:

array(
       'User' => array(
               'password' => '*****',
               'nome' => 'Engenharia',
               'username' => '[email protected]',
               'confirm_password' => '123',
       ),
       'Endereco' => array(
               (int) 0 => array(
                    'cidade_id' => '3091',
                          'cep' => '96032012',
                          'rua' => 'Conde de porto alegre',
                          'numero' => '420',
                          'bairro' => 'Porto',
                          'complemento' => 'Empresa'
                  )
        ),
        'UserGroup' => array(
                 'group_id' => '2',
         )
)

I removed the field nome table UserGroup that was in conflict and used the nome (that I needed) another existing table in the bank, so I made only one relationship on Controller to call this table and worked perfectly!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.