We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon save error . Error when insert Phalcon\Mvc\Model::_doLowInsert(): Property should be string

Create database :

  CREATE TABLE api_failed_logins
  (
    user_id INT UNSIGNED NOT NULL,
    logs LONGTEXT,
    ip VARCHAR(15) NOT NULL,
    PRIMARY KEY (user_id, ip)
  );

Create model with metaData

public function metaData()
    {
        return array(

            //Every column in the mapped table
            MetaData::MODELS_ATTRIBUTES => array(
                 'user_id', 'ip','logs'
            ),

            //Every column part of the primary key
            MetaData::MODELS_PRIMARY_KEY => array(
                'user_id','ip'
            ),

            //Every column that isn't part of the primary key
            MetaData::MODELS_NON_PRIMARY_KEY => array(
                 'logs'
            ),

            //Every column that doesn't allows null values
            MetaData::MODELS_NOT_NULL => array(
                'user_id','ip'
            ),
            //MetaData::MODELS_DEFAULT_VALUES => array('user_id','ip'),
            //MetaData::MODELS_DEFAULT_VALUES => array(NULL,NULL),
           // MetaData::MODELS_DEFAULT_VALUES => array(NULL),
            //MetaData::MODELS_DEFAULT_VALUES => array(),
            //MetaData::MODELS_DEFAULT_VALUES => array('user_id'=>NULL,'ip'=>NULL),

            //Every column and their data types
            MetaData::MODELS_DATA_TYPES => array(
                'user_id' => Column::TYPE_INTEGER,
                'logs' => Column::TYPE_TEXT,
                'ip' => Column::TYPE_VARCHAR,
            ),

            //The columns that have numeric data types
            MetaData::MODELS_DATA_TYPES_NUMERIC => array(
                'user_id' => true
            ),

            //The identity column, use boolean false if the model doesn't have
            //an identity column
            MetaData::MODELS_IDENTITY_COLUMN => array('user_id','ip'),

            //How every column must be bound/casted
            MetaData::MODELS_DATA_TYPES_BIND => array(
                'user_id' => Column::BIND_PARAM_INT,
                'logs' => Column::BIND_PARAM_STR,
                'ip' => Column::BIND_PARAM_STR,
            ),

            //Fields that must be ignored from INSERT SQL statements
            MetaData::MODELS_AUTOMATIC_DEFAULT_INSERT => array(
                //'created' => 100
            ),

            //Fields that must be ignored from UPDATE SQL statements
            MetaData::MODELS_AUTOMATIC_DEFAULT_UPDATE => array(
                // 'modified' => true
            ),
            MetaData::MODELS_DEFAULT_VALUES => array(),
        );
    }

Save on controller

  $failedLogins = new VApi\Models\FailedLogins();   
  $failedLogins->user_id = rand(1,100);
  $failedLogins->ip = '101.100.100.100';
  $logs[] = time();
  $failedLogins->logs = json_encode($logs);   
  if($failedLogins->save()) {
        $e = error_get_last();
        **print_r($e);**
        $app->response->setJsonContent(array(
        'status' => 'SUCCESS',
        'data' => array('login'=>1,'logs'=>$logs)));
  }else {
        $errors = array();
        foreach ($failedLogins->getMessages() as $message) {
        $errors[]= $message;
        }
        $app->response->setJsonContent(array('status' => 'ERROR', 'messages' => $errors));
  }

Insert data ok but show Error on PHP.

      array(4) {
          ["type"]=>
          int(2)
          ["message"]=>
          string(60) "Phalcon\Mvc\Model::_doLowInsert(): Property should be string"
          ["file"]=>
          string(70) "D:\HoangVu\xampp_56\htdocs\phalcon\pha-api\app\v\failed_logins\log.php"
          ["line"]=>
          int(29)
    }
edited Jun '15

I have fixed metaData and run perfect

MetaData::MODELS__IDENTITY_COLUMN => false,

and

MetaData::MODELS__DEFAULT_VALUES => array('logs'=>null),

public function metaData()
{
    return array(

        //Every column in the mapped table
        MetaData::MODELS_ATTRIBUTES => array(
             'user_id', 'logs','ip',
        ),

        //Every column part of the primary key
        MetaData::MODELS_PRIMARY_KEY => array(
            'user_id','ip'
        ),

        //Every column that isn't part of the primary key
        MetaData::MODELS_NON_PRIMARY_KEY => array(
             'logs'
        ),

        //Every column that doesn't allows null values
        MetaData::MODELS_NOT_NULL => array(
            'user_id','ip'
        ),
        //MetaData::MODELS_DEFAULT_VALUES => array('user_id','ip'),
        //MetaData::MODELS_DEFAULT_VALUES => array(NULL,NULL),
       // MetaData::MODELS_DEFAULT_VALUES => array(NULL),
        //MetaData::MODELS_DEFAULT_VALUES => array(),
        //MetaData::MODELS_DEFAULT_VALUES => array('user_id'=>NULL,'ip'=>NULL),

        //Every column and their data types
        MetaData::MODELS_DATA_TYPES => array(
            'user_id' => Column::TYPE_INTEGER,
            'logs' => Column::TYPE_TEXT,
            'ip' => Column::TYPE_VARCHAR,
        ),

        //The columns that have numeric data types
        MetaData::MODELS_DATA_TYPES_NUMERIC => array(
            'user_id' => true
        ),

        //The identity column, use boolean false if the model doesn't have
        //an identity column
        MetaData::MODELS_IDENTITY_COLUMN => false,

        //How every column must be bound/casted
        MetaData::MODELS_DATA_TYPES_BIND => array(
            'user_id' => Column::BIND_PARAM_INT,
            'logs' => Column::BIND_PARAM_STR,
            'ip' => Column::BIND_PARAM_STR,
        ),

        //Fields that must be ignored from INSERT SQL statements
        MetaData::MODELS_AUTOMATIC_DEFAULT_INSERT => array(
            //'created' => 100
        ),

        //Fields that must be ignored from UPDATE SQL statements
        MetaData::MODELS_AUTOMATIC_DEFAULT_UPDATE => array(
            // 'modified' => true
        ),
        MetaData::MODELS_DEFAULT_VALUES => array('logs'=>null),
    );
}