Problem converting Post->Comment demo

Hi,

I’m a recent Yii adopter and this is my very first post. Nice to meet you all.

I am building an app starting with two objects having a 1:N relationship, a Statement that can have many Debates on it. Learning Yii as I go, I thought I’d leverage the demo of Post->Comment. But I’m getting a problem.

I’ve built Statement->Debate in parallel with Post->Comment, taking code snippets and converting them as I go. Everything is working fine until I want to save a new Debate (Comment) from the Statement (Post) view page. I get the following error:

===== BEGIN =====

CDbException

CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 1467 Failed to read auto-increment value from storage engine. The SQL statement executed was: INSERT INTO tbl_debate (description, typecode, statementid, reasonid, sourceid, createuserid, createdate, modifieduserid, modifieddate) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4, :yp5, :yp6, :yp7, :yp8)

/Applications/MAMP/htdocs/yii/framework/db/CDbCommand.php(336)

324 return $n;

325 }

326 catch(Exception $e)

327 {

328 if($this->_connection->enableProfiling)

329 Yii::endProfile(‘system.db.CDbCommand.execute(’.$this->getText().’)’,‘system.db.CDbCommand.execute’);

330 $errorInfo = $e instanceof PDOException ? $e->errorInfo : null;

331 $message = $e->getMessage();

332 Yii::log(Yii::t(‘yii’,‘CDbCommand::execute() failed: {error}. The SQL statement executed was: {sql}.’,

333 array(’{error}’=>$message, ‘{sql}’=>$this->getText().$par)),CLogger::LEVEL_ERROR,‘system.db.CDbCommand’);

334 if(YII_DEBUG)

335 $message .= '. The SQL statement executed was: '.$this->getText().$par;

336 throw new CDbException(Yii::t(‘yii’,‘CDbCommand failed to execute the SQL statement: {error}’,

337 array(’{error}’=>$message)),(int)$e->getCode(),$errorInfo);

338 }

339 }

340

341 /**

342 * Executes the SQL statement and returns query result.

343 * This method is for executing an SQL query that returns result set.

344 * @param array $params input parameters (name=>value) for the SQL execution. This is an alternative

345 * to {@link bindParam} and {@link bindValue}. If you have multiple input parameters, passing

346 * them in this way can improve the performance. Note that if you pass parameters in this way,

347 * you cannot bind parameters or values using {@link bindParam} or {@link bindValue}, and vice versa.

348 * binding methods and the input parameters this way can improve the performance.

Stack Trace

#0

  • /Applications/MAMP/htdocs/yii/framework/db/ar/CActiveRecord.php(1017): CDbCommand->execute()

#1

  • /Applications/MAMP/htdocs/yii/framework/db/ar/CActiveRecord.php(781): CActiveRecord->insert(null)

#2

– /Applications/MAMP/htdocs/alpha1/protected/models/Statement.php(233): CActiveRecord->save()

228 //if(Yii::app()->params[‘debateNeedApproval’])

229 //$comment->status=Comment::STATUS_PENDING;

230 //else

231 //$comment->status=Comment::STATUS_APPROVED;

232 $debate->statementid=$this->id;

233 return $debate->save();

234 }

235

236

237

238

===== END =====

Any thoughts?

Thank you all in advance for your time and efforts.

-Jim

Try ALTER TABLE ``tbl_debate` AUTO_INCREMENT =1