• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

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

Jake Bunce

XenForo moderator
Staff member
#3
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.
 

Mythotical

Well-known member
#4
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.
 
R

ragtek

Guest
#8
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*
 

Mythotical

Well-known member
#9
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.
 
S

Syndol

Guest
#10
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');
 

Mythotical

Well-known member
#11
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.
 
S

Syndol

Guest
#12
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));
}
 

Mythotical

Well-known member
#18
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