Mysqli statement execute error : Field 'username' doesn't have a default value

Mysqli statement execute error : Field 'username' doesn't have a default value

That means there is a "username" field in the table that is not included in the datawriter. If this is intentional then you need to modify the definition of that field in the database so that it is nullable or has a default value. Otherwise it needs to be added to your datawriter.
 
My datawriter is Currency.php above.

Jake, the username field is coming from posting. I'll add it to my datawriter to see if that fixes it.
 
XenForo_DataWriters get method:

/**
* Gets data related to this object regardless of where it is defined (new or old).
*
* @param string Field name
* @param string Table name, if empty loops through tables until first match
*
* @return mixed Returns null if the specified field could not be found.
*/
public function get($field, $tableName = '')
{



and how you're using it:

$userId = $this->get('user_id', XenForo_Input::UINT);



so you're copying bdbank and selling it?:D
/*protected function _deleteAttachments()[/QUOTE]
// the work (should be done) here will be done in bdBank_Model_Attachment (extends XenForo_Model_Attachment)
return parent::_deleteAttachments();
}*/
*scnr*
 
XenForo_DataWriters get method:

/**
* Gets data related to this object regardless of where it is defined (new or old).
*
* @param string Field name
* @param string Table name, if empty loops through tables until first match
*
* @return mixed Returns null if the specified field could not be found.
*/
public function get($field, $tableName = '')
{



and how you're using it:

$userId = $this->get('user_id', XenForo_Input::UINT);



so you're copying bdbank and selling it?:D
/*protected function _deleteAttachments()
// the work (should be done) here will be done in bdBank_Model_Attachment (extends XenForo_Model_Attachment)
return parent::_deleteAttachments();
}*/
*scnr*
No I used it as an example for myself. It is not even used as you can tell the whole thing is commented out. Honestly I don't even know why I left that in there, I don't intend to have users lose points when they delete an attachment. LOL I'm surprised you noticed anyway.

Ok I thought I understood what you meant but obviously I don't. I added the line to my datawriter but still get the same error.
 
OK I'll bite :)
Three comments:
  1. Where is the protected function _getFields() in your DataWriter (Gets the fields that are defined for the table. See parent for explanation.)
  2. Your table must have a username field that is set to required (not null) - we don't know what your table looks like from above info
  3. Why the + between $pointsModel->assignUserPoints($userId, 'thread') + $pointsModel->assignUserPoints($userId, 'size');
 
OK I'll bite :)
Three comments:
  1. Where is the protected function _getFields() in your DataWriter (Gets the fields that are defined for the table. See parent for explanation.)
  2. Your table must have a username field that is set to required (not null) - we don't know what your table looks like from above info
  3. Why the + between $pointsModel->assignUserPoints($userId, 'thread') + $pointsModel->assignUserPoints($userId, 'size');
Your behind. LOL Number 2 on your list is no longer an issue, I was not calling the getExistingData for the writer.

1. You mean in DataWriter/DiscussionMessage/Post.php ?
3. If conditions are ran that if the post size check passes then they are given points for the creating of a new thread plus the points for passing the post size check.
 
At any rate shouldn't you be returning the name of YOUR table instead of xf_user ?
PHP:
protected function _getFields()
{
    return array(
        'xf_user' => array(
            'user_id' => array('type' => self::TYPE_UINT),
            'mypoints_currency' => array('type' => self::TYPE_UINT, 'default' => 0)
        )
    );
}
 
protected function _getExistingData($data)
{
    if (!$userId = $this->_getExistingPrimaryKey($data, 'user_id')) {
        return false;
    }
 
    return array('xf_user' => $this->getModelFromCache('MyPoints_Model_Currency')->getUserPointsId($userId));
}
 
Then you should use the xenforo user datawriter instead of an own
 
How would I do that? The xenforo user datawriter wouldn't have mypoints_currency as a _getFields().
 
Thanks to everyone who posted and gave me insight, I found an alternative method that works and saves me a headache.

Ragtek, I especially thank you, at first I hate you referred to reading but after awhile I realize reading was the best method so if you ever see me posting help questions or coding issues then please do direct me to some reading. :D
 
Top Bottom