Not a bug 'nf_discord_enable' doesn't have a default value if i create a node

Tealk

Well-known member
Affected version
v2.0.0
Hallo,

I have create a copy from my Forum and have upgraded to xf2 but if i try to creat a node i get this error:

Code:
XF\Db\Exception: MySQL query error [1364]: Field 'nf_discord_enable' doesn't have a default value src/XF/Db/AbstractStatement.php:212
Generated by: Tealk Nov 29, 2017 at 2:21 PM
Stack trace
INSERT  INTO xf_forum (`node_id`, `allow_posting`, `allow_poll`, `moderate_threads`, `moderate_replies`, `count_messages`, `find_new`, `allowed_watch_notifications`, `default_sort_order`, `default_sort_direction`, `list_date_limit_days`, `default_prefix_id`, `require_prefix`, `min_tags`, `discussion_count`, `message_count`, `last_post_id`, `last_post_date`, `last_post_user_id`, `last_post_username`, `last_thread_title`, `last_thread_prefix_id`, `field_cache`, `prefix_cache`, `prompt_cache`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
------------

#0 src/XF/Db/Mysqli/Statement.php(174): XF\Db\AbstractStatement->getException('MySQL query err...', 1364, 'HY000')
#1 src/XF/Db/Mysqli/Statement.php(69): XF\Db\Mysqli\Statement->getException('MySQL query err...', 1364, 'HY000')
#2 src/XF/Db/AbstractAdapter.php(69): XF\Db\Mysqli\Statement->execute()
#3 src/XF/Db/AbstractAdapter.php(145): XF\Db\AbstractAdapter->query('INSERT  INTO xf...', Array)
#4 src/XF/Mvc/Entity/Entity.php(1381): XF\Db\AbstractAdapter->insert('xf_forum', Array)
#5 src/XF/Mvc/Entity/Entity.php(1113): XF\Mvc\Entity\Entity->_saveToSource()
#6 src/XF/Mvc/Entity/Entity.php(1131): XF\Mvc\Entity\Entity->save(true, false)
#7 src/XF/Mvc/FormAction.php(69): XF\Mvc\Entity\Entity->save(true, false)
#8 src/XF/Mvc/FormAction.php(159): XF\Mvc\FormAction->XF\Mvc\{closure}(Object(XF\Mvc\FormAction))
#9 src/XF/Admin/Controller/AbstractNode.php(110): XF\Mvc\FormAction->run()
#10 src/XF/Mvc/Dispatcher.php(249): XF\Admin\Controller\AbstractNode->actionSave(Object(XF\Mvc\ParameterBag))
#11 src/XF/Mvc/Dispatcher.php(88): XF\Mvc\Dispatcher->dispatchClass('XF:Forum', 'Save', 'json', Object(XF\Mvc\ParameterBag), 'nodes', Object(XF\Admin\Controller\Forum), NULL)
#12 src/XF/Mvc/Dispatcher.php(41): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#13 src/XF/App.php(1879): XF\Mvc\Dispatcher->run()
#14 src/XF.php(328): XF\App->run()
#15 admin.php(13): XF::runApp('XF\\Admin\\App')
#16 {main}
Request state
array(4) {
  ["url"] => string(24) "/admin.php?forums/0/save"
  ["referrer"] => string(61) "http://x2.anzahcraft.de/admin.php?forums/add&parent_node_id=0"
  ["_GET"] => array(1) {
    ["forums/0/save"] => string(0) ""
  }
  ["_POST"] => array(12) {
    ["node"] => array(7) {
      ["title"] => string(7) "Support"
      ["description"] => string(0) ""
      ["node_name"] => string(0) ""
      ["parent_node_id"] => string(1) "0"
      ["display_order"] => string(4) "1000"
      ["display_in_list"] => string(1) "1"
      ["navigation_id"] => string(0) ""
    }
    ["allow_posting"] => string(1) "1"
    ["min_tags"] => string(1) "0"
    ["allowed_watch_notifications"] => string(3) "all"
    ["default_sort_order"] => string(14) "last_post_date"
    ["default_sort_direction"] => string(4) "desc"
    ["list_date_limit_days"] => string(1) "0"
    ["default_prefix_id"] => string(2) "-1"
    ["_xfToken"] => string(8) "********"
    ["_xfRequestUri"] => string(38) "/admin.php?forums/add&parent_node_id=0"
    ["_xfWithData"] => string(1) "1"
    ["_xfResponseType"] => string(4) "json"
  }
}
 
Specifically due to its (incorrect) schema declaration -- it would break whenever the add-on gets disabled. You may need to manually change/remove the column if the author can't tell you what change(s) are needed to it.
 
Specifically due to its (incorrect) schema declaration
Just a wee note; maybe this would be useful to log in the developer docs, something to the effect of "if you are adding a column to a table that doesn't belong to your add-on, you must make sure the column has a default value to prevent errors if your add-on is disabled".

Only, y'know, written by someone who's not still trying to wake up :p

If I can find the dev docs github I'll log a feature request there. EDIT: Done - https://github.com/xenforo-ltd/docs/issues/29


Fillip
 
@Tealk I took a look, running this sql query should do the trick:
SQL:
ALTER TABLE `xf_forum` MODIFY COLUMN `nf_discord_enable` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0';

BURN THE WITCH! :mad:

:p


Fillip
I deserve it. :(

Not sure how I missed it lol, the other column I add to that table has a default value. Must've been just waking up too. :D
 
this worked for my install as nixfifty discord integration broke with the upgrade from xenforo 1.4 to 2.0.

To add a bit of detail for those looking at doing this but not so high on the tech side of things:

Command line on your install, change USER to your mysql user for your database, possibly -u root and after you hit enter it will ask for your mysql database password. Afterwards double check xenforo to ensure that it resolved your issue creating new nodes.

Bash:
mysql -u USER -p -e 'ALTER TABLE `xf_forum` MODIFY COLUMN `nf_discord_enable` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0';' xenforo
 
Top Bottom