1. 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

Discussion in 'XenForo Development Discussions' started by Mythotical, Jul 5, 2012.

  1. Mythotical

    Mythotical Well-Known Member

    Removed
     
  2. ragtek

    ragtek Guest

    and what's the code of points datawriter?
     
  3. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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.
     
  4. Mythotical

    Mythotical Well-Known Member

    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.
     
  5. Mythotical

    Mythotical Well-Known Member

    Ok tried adding username to my datawriter, still get the same error.

    The Currency.php code above is the same for the UserPoints.php datawriter.
     
  6. ragtek

    ragtek Guest

    Then=> as jack said:
     
  7. Mythotical

    Mythotical Well-Known Member

    Please see posts below. 'username' error has been fixed.
     
  8. ragtek

    ragtek Guest

    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*
     
  9. Mythotical

    Mythotical Well-Known Member

    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.
     
  10. Syndol

    Syndol Guest

    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');
     
  11. Mythotical

    Mythotical Well-Known Member

    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.
     
  12. Syndol

    Syndol Guest

    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));
    }
     
  13. Mythotical

    Mythotical Well-Known Member

    Nope, my field is in the xf_user table. mypoints_currency is the field in xf_user.
     
  14. ragtek

    ragtek Guest

    Then you should use the xenforo user datawriter instead of an own
     
  15. Mythotical

    Mythotical Well-Known Member

    How would I do that? The xenforo user datawriter wouldn't have mypoints_currency as a _getFields().
     
  16. Syndol

    Syndol Guest

    Extend it!
     
  17. Mythotical

    Mythotical Well-Known Member

    Oh duh, had a dumb moment when I posted that.
     
  18. Mythotical

    Mythotical Well-Known Member

    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
     

Share This Page