title: Assignment & gradebook error
body: <p>With some courses, I am receiving a dmlwriteexception when trying to add an assignment or open the gradebook with the following stack trace:</p>
  
  <pre><code>Debug info: Column 'grademax' cannot be null
  INSERT INTO mdl_grade_items (courseid,categoryid,itemname,itemtype,itemmodule,iteminstance,itemnumber,iteminfo,idnumber,calculation,gradetype,grademax,grademin,scaleid,outcomeid,gradepass,multfactor,plusfactor,aggregationcoef,aggregationcoef2,sortorder,display,decimals,locked,locktime,needsupdate,weightoverride,timecreated,timemodified,hidden) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
  [array (
  0 =&gt; '206',
  1 =&gt; NULL,
  2 =&gt; NULL,
  3 =&gt; 'course',
  4 =&gt; NULL,
  5 =&gt; '73',
  6 =&gt; NULL,
  7 =&gt; NULL,
  8 =&gt; NULL,
  9 =&gt; NULL,
  10 =&gt; 1,
  11 =&gt; NULL,
  12 =&gt; 0,
  13 =&gt; NULL,
  14 =&gt; NULL,
  15 =&gt; 0,
  16 =&gt; 1,
  17 =&gt; 0,
  18 =&gt; 0,
  19 =&gt; 0,
  20 =&gt; 1,
  21 =&gt; 0,
  22 =&gt; NULL,
  23 =&gt; 0,
  24 =&gt; 0,
  25 =&gt; 1,
  26 =&gt; 0,
  27 =&gt; 1474281854,
  28 =&gt; 1474281854,
  29 =&gt; 0,
  )]
  Error code: dmlwriteexception
  
  ×Stack trace:
  
  ·         line 477 of /lib/dml/moodle_database.php: dml_write_exception thrown
  
  ·         line 1172 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database-&gt;query_end()
  
  ·         line 1218 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database-&gt;insert_record_raw()
  
  ·         line 343 of /lib/grade/grade_object.php: call to mysqli_native_moodle_database-&gt;insert_record()
  
  ·         line 472 of /lib/grade/grade_item.php: call to grade_object-&gt;insert()
  
  ·         line 2259 of /lib/grade/grade_category.php: call to grade_item-&gt;insert()
  
  ·         line 2230 of /lib/grade/grade_category.php: call to grade_category-&gt;get_grade_item()
  
  ·         line 2447 of /lib/grade/grade_category.php: call to grade_category-&gt;load_grade_item()
  
  ·         line 897 of /lib/gradelib.php: call to grade_category-&gt;is_course_category()
  
  ·         line 850 of /course/moodleform_mod.php: call to grade_get_categories_menu()
  
  ·         line 191 of /mod/assign/mod_form.php: call to moodleform_mod-&gt;standard_grading_coursemodule_elements()
  
  ·         line 201 of /lib/formslib.php: call to mod_assign_mod_form-&gt;definition()
  
  ·         line 95 of /course/moodleform_mod.php: call to moodleform-&gt;__construct()
  
  ·         line 255 of /course/modedit.php: call to moodleform_mod-&gt;__construct()
  
  ×Output buffer: &lt;br /&gt; &lt;b&gt;Notice&lt;/b&gt;: Undefined property: stdClass::$requiremodintro in &lt;b&gt;/var/www/html/moodle/course/moodleform_mod.php&lt;/b&gt; on line &lt;b&gt;894&lt;/b&gt;&lt;br /&gt; &lt;br /&gt; &lt;b&gt;Notice&lt;/b&gt;: Undefined property: stdClass::$gradepointdefault in &lt;b&gt;/var/www/html/moodle/course/moodleform_mod.php&lt;/b&gt; on line &lt;b&gt;814&lt;/b&gt;&lt;br /&gt; &lt;br /&gt; &lt;b&gt;Notice&lt;/b&gt;: Undefined property: stdClass::$gradepointdefault in &lt;b&gt;/var/www/html/moodle/lib/grade/grade_item.php&lt;/b&gt; on line &lt;b&gt;270&lt;/b&gt;&lt;br /&gt; &lt;br /&gt; &lt;b&gt;Notice&lt;/b&gt;: Undefined property: stdClass::$gradepointdefault in &lt;b&gt;/var/www/html/moodle/lib/grade/grade_item.php&lt;/b&gt; on line &lt;b&gt;270&lt;/b&gt;&lt;br /&gt;
  </code></pre>
  
  <p>It does not happen in all courses and I am using Moodle 3.1 on CentOS.</p>
  
  <p>Please, how can I correct this?</p>