Problems with Crud

I am developing one application in postgre and I am having problems with the Crud.

First he was disturbed by the fact that the table is with lowercase letters and creating the model the table name is capitalized. Resolved by changing the tableName variable for all models. But I wonder if you have a better solution.

Another problem concerns the crud. When I went into a view I realized that he did not score the required fields, and then to save (even though I completed all the fields), has sql error.

Could anyone help me?

Thank you all.

With problem

>> cmodel User

Warning: the table ‘User’ does not exist in the database.

generate User.php

without problem

>> cmodel user

generate user.php

The following model classes are successfully generated:


next step

>> crud user

Error: Table "User" does not have a primary key.

>> crud User

Error: Table "User" does not have a primary key.


If you have a ‘db’ database connection, you can test these models now with:



>> $model=user::model()->find();

exception ‘CDbException’ with message ‘CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘LIMIT 1’ at line 1’ in /opt/yii/framework/db/CDbCommand.php:372

Stack trace:

#0 /opt/yii/framework/db/CDbCommand.php(281): CDbCommand->queryInternal(‘fetch’, 2, Array)

#1 /opt/yii/framework/db/ar/CActiveRecord.php(1451): CDbCommand->queryRow()

#2 /opt/yii/framework/db/ar/CActiveRecord.php(1480): CActiveRecord->query(Object(CDbCriteria))

#3 /opt/yii/framework/cli/commands/ShellCommand.php(145) : eval()'d code(1): CActiveRecord->find()

#4 /opt/yii/framework/cli/commands/ShellCommand.php(145): eval()

#5 /opt/yii/framework/cli/commands/ShellCommand.php(99): ShellCommand->runShell()

#6 /opt/yii/framework/console/CConsoleCommandRunner.php(62): ShellCommand->run(Array)

#7 /opt/yii/framework/console/CConsoleApplication.php(88): CConsoleCommandRunner->run(Array)

#8 /opt/yii/framework/base/CApplication.php(135): CConsoleApplication->processRequest()

#9 /opt/yii/framework/yiic.php(31): CApplication->run()

#10 /opt/yii/framework/yiic(15): require_once(’/opt/yii/framew…’)

#11 {main}


Could anyone help me?

Thank you all.

Not sure if it helps, but you could try to specify the table name as second parameter for the model command:

>> model User user

Mike. Thank. It worked :D