Yii2: Failed to create the object for unknown reason.

Created on 18 Oct 2016  路  3Comments  路  Source: yiisoft/yii2

I'm got Exception 'Failed to create the object for unknown reason.'

$model->save() == false
and
$model->hasErrors() == false

In what situations can it be?
This is magic of Yii2? We don't know what happend

question

Most helpful comment

look beforeValidate should return true if valid

All 3 comments

look beforeValidate should return true if valid

@psfpro this exception throwed in one place: https://github.com/yiisoft/yii2/blob/495553616dc41b9a5db141931388d9502d19eb13/framework/rest/CreateAction.php#L56

Please ensure what you model has rules() for attributes required by DB and Yii::$app->getRequest()->getBodyParams() has model attributes.

For debug you may dump $model after load in yii/rest/CreateAction.php

_This is an automated comment, triggered by adding the label question._

Please note, that the GitHub Issue Tracker is for bug reports and feature requests only.

We are happy to help you on the support forum, on IRC (#yii on freenode), or Gitter.

Please use one of the above mentioned resources to discuss the problem.
If the result of the discussion turns out that there really is a bug in the framework, feel free to
come back and provide information on how to reproduce the issue. This issue will be closed for now.

Was this page helpful?
0 / 5 - 0 ratings