问题
I got an error CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 1364 Field 'editedbyid' doesn't have a default value. The SQL statement executed was:
INSERT INTO `pos` (`serialnumber`, `posmodelid`, `active`, `created`, `updated`, `forapproval`, `approvedbyid`) VALUES (:yp0, :yp1, 1, NOW(), :yp2, :yp3, :yp4)"
I'm using MySQL, PHP and uii framework. How can i resolve this?
回答1:
The field editedbyid in your database table doesn't have a default value configured.
So, when inserting a new row, the database engine doesn't know which value it must set for the editedbyid field.
possible solutions are:
1. set a default value:
With phpmyadmin for example, select the pos table, enter a default value for the 'editedbyid' field.
2. insert a value for the 'editedbyid' field:
INSERT INTO `pos` (`serialnumber`, `posmodelid`, `active`, `created`, `updated`, `forapproval`, `approvedbyid`, `editedbyid`) VALUES (:yp0, :yp1, 1, NOW(), :yp2, :yp3, :yp4, 0)"
EDIT: Also read this question and answers about default values.
回答2:
Maybe Try running SET GLOBAL sql_mode='' or edit your my.cnf to make sure you aren't setting STRICT_ALL_TABLES or the like. Yii issues
来源:https://stackoverflow.com/questions/11733266/field-x-doesnt-have-a-default-value