Search code examples
phpmysqlyiiprimary-keyinsert-update

Column name must be either a string or an array. yii


while I am updating record it display above error.

message id seems like this - 1536126282209770000

$q = new CDbCriteria(array(
            'condition' =>  'tokenId = :btokenid',
            'params' => array(
                ':btokenid' => $tokenId,
            ),
        ));

        $record = self::model()->find($q);

        $record->messageId = $messageId;
            if (!$record->save()) {
                $_errors = current($record->getErrors());
                throw new Exception($_errors[0]);
            }

I added 2 primary keys for table.

table structure:

table structure


Solution

  • After adding primary keys to table need to flush the cache

    To refresh the database cache : Load all tables of the application in the schema

    Yii::app()->db->schema->getTables();

    clear the cache of all loaded tables

    Yii::app()->db->schema->refresh();
    

    If you want to refresh only one table, you can also do :

    Yii::app()->db->schema->getTable('tablename', true);
    

    After that It works fine.