Error Info: Array ( [0] => 23502 [1] => 7 [2] => ERROR: null value in column "user_id" of relation "content_ratio" violates not-null constraint DETAIL: Failing row contains (app\models\content\Song, s:5:"60526";, null, 1, 1711711885). )
in /var/www/ya-poyu/vendor/yiisoft/yii2/db/Command.php at line 1290
$exceptionClass = '\yii\db\Exception'; foreach ($this->exceptionMap as $error => $class) { if (strpos($e->getMessage(), $error) !== false) { $exceptionClass = $class; } } $message = $e->getMessage() . "\nThe SQL being executed was: $rawSql"; $errorInfo = $e instanceof \PDOException ? $e->errorInfo : null; return new $exceptionClass($message, $errorInfo, (int)$e->getCode(), $e); } /** * Returns a value indicating whether a SQL statement is for read purpose. * @param string $sql the SQL statement * @return bool whether a SQL statement is for read purpose. */ public function isReadQuery($sql) {
} else { $this->pdoStatement->execute(); } break; } catch (\Exception $e) { $rawSql = $rawSql ?: $this->getRawSql(); $e = $this->db->getSchema()->convertException($e, $rawSql); if ($this->_retryHandler === null || !call_user_func($this->_retryHandler, $e, $attempt)) { throw $e; } } } }
$this->prepare(true); try { $profile and Yii::beginProfile($rawSql, 'yii\db\Command::query'); $this->internalExecute($rawSql); if ($method === '') { $result = new DataReader($this); } else { if ($fetchMode === null) { $fetchMode = $this->fetchMode;
* @return array|false the first row (in terms of an array) of the query result. False is returned if the query * results in nothing. * @throws Exception execution failed */ public function queryOne($fetchMode = null) { return $this->queryInternal('fetch', $fetchMode); } /** * Executes the SQL statement and returns the value of the first column in the first row of data. * This method is best used when only a single value is needed for a query. * @return string|null|false the value of the first column in the first row of the query result.
} $sql .= ' RETURNING ' . implode(', ', $returning); } $command = $this->db->createCommand($sql, $params); $command->prepare(false); $result = $command->queryOne(); return !$command->pdoStatement->rowCount() ? false : $result; } /** * Loads multiple types of constraints and returns the specified ones.
protected function insertInternal($attributes = null) { if (!$this->beforeSave(true)) { return false; } $values = $this->getDirtyAttributes($attributes); if (($primaryKeys = static::getDb()->schema->insert(static::tableName(), $values)) === false) { return false; } foreach ($primaryKeys as $name => $value) { $id = static::getTableSchema()->columns[$name]->phpTypecast($value); $this->setAttribute($name, $id); $values[$name] = $id;
if ($runValidation && !$this->validate($attributes)) { Yii::info('Model not inserted due to validation error.', __METHOD__); return false; } if (!$this->isTransactional(self::OP_INSERT)) { return $this->insertInternal($attributes); } $transaction = static::getDb()->beginTransaction(); try { $result = $this->insertInternal($attributes); if ($result === false) {
* meaning all attributes that are loaded from DB will be saved. * @return bool whether the saving succeeded (i.e. no validation errors occurred). */ public function save($runValidation = true, $attributeNames = null) { if ($this->getIsNewRecord()) { return $this->insert($runValidation, $attributeNames); } return $this->update($runValidation, $attributeNames) !== false; } /**
$obj->class_name = $model->className(); $obj->class_id = serialize($model->primaryKey); $obj->user_id = $user_id; $obj->vote = $vote; $obj->time = time(); return $obj->save(); } /** * @param ActiveRecord $model * @return ActiveQuery */
Profile::updateAllCounters(['ratio'=>-$ratioMinus],['user_id' => $this->created_by]); return parent::beforeDelete(); } public function addVote($user_id){ if(ContentRatio::addVoteByModel($this, $user_id)){ $this->updateCounters(['ratio' => 1]); Profile::updateAllCounters(['ratio'=>1],['user_id' => $this->created_by]); return true; } return false;
if (!\Yii::$app->user->id) { $this->redirect(['view', 'id' => $id]); } if (!\Yii::$app->session->get($sessionKey, false)) { /** @var Song $model */ $model = $this->findModel($id); $model->addVote(\Yii::$app->user->id); \Yii::$app->session->set($sessionKey, true); if(\Yii::$app->request->isAjax) return 1; } else { return 0; }
$args = $this->controller->bindActionParams($this, $params); Yii::debug('Running action: ' . get_class($this->controller) . '::' . $this->actionMethod . '()', __METHOD__); if (Yii::$app->requestedParams === null) { Yii::$app->requestedParams = $args; } return call_user_func_array([$this->controller, $this->actionMethod], $args); } }
} $result = null; if ($runAction && $this->beforeAction($action)) { // run the action $result = $action->runWithParams($params); $result = $this->afterAction($action, $result); // call afterAction on modules foreach ($modules as $module) { /* @var $module Module */
$parts = $this->createController($route); if (is_array($parts)) { /* @var $controller Controller */ list($controller, $actionID) = $parts; $oldController = Yii::$app->controller; Yii::$app->controller = $controller; $result = $controller->runAction($actionID, $params); if ($oldController !== null) { Yii::$app->controller = $oldController; } return $result; }
$params = $this->catchAll; unset($params[0]); } try { Yii::debug("Route requested: '$route'", __METHOD__); $this->requestedRoute = $route; $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; } $response = $this->getResponse(); if ($result !== null) {
{ try { $this->state = self::STATE_BEFORE_REQUEST; $this->trigger(self::EVENT_BEFORE_REQUEST); $this->state = self::STATE_HANDLING_REQUEST; $response = $this->handleRequest($this->getRequest()); $this->state = self::STATE_AFTER_REQUEST; $this->trigger(self::EVENT_AFTER_REQUEST); $this->state = self::STATE_SENDING_RESPONSE; $response->send();
require(__DIR__ . '/../vendor/autoload.php'); require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); $config = require(__DIR__ . '/../config/web.php'); (new yii\web\Application($config))->run();
$_GET = [ 'id' => '60526', ]; $_SESSION = [ '__flash' => [], ];