reason :
In the middle of the control system encountered a user batch allocation of roles, just beginning to think of is the loop insert, but immediately to the negative, the recycling database developers of the big bogey ah, so find the manual to find data write see Bulk operation: AddAll (), test success, thought everything is all right, But when the second operation is prompted to fail, to find the reason, originally the database already exists in the data AddAll () No overwrite caused the error
Workaround :
Find thinkphp source turned to library/think/model.class.php found AddAll method: Public Function AddAll ($dataList, $options =array (), $ Replace=false) So the second understand, replace must be asked if you overwrite the existing data, so modify my AddAll method is: $user->addall ($data, Array (), true): Test the problem again.
This article is from the "Love Xiao" blog, please be sure to keep this source http://aixiao.blog.51cto.com/7244439/1410495