Field 'x' doesn't have a default value

。_饼干妹妹 提交于 2021-02-17 04:43:44

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!