OpenID error Field 'country' doesn't have a default value

OpenID error Field 'country' doesn't have a default value

by Conor Bradley -
Number of replies: 3

We're currently trying to set up the Microsoft plugins for Open ID Connect login.

After setting all the Azure AD settings etc. in Moodle we're running into issues with our first test user.

When I try a login I run into the error screen below 

login screen

On checking the server error logs we see there's an entry below:

[Thu Jul 30 10:00:05.781170 2020] [php7:notice] [pid 25848] [client 192.168.231.159:55530] Default exception handler:
Error writing to database Debug: Field 'country' doesn't have a default value\n
INSERT INTO mdl_user (lang,idnumber,firstname,lastname,email,city,auth,username,confirmed,lastip,timecreated,timemodified,mnethostid,calendartype,maildisplay,mailformat,maildigest,autosubscribe,trackforums) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)\n
[array (\n
  0 => 'en',\n
  1 => 'cbteststu0567@students.xxx.ac.uk',\n
  2 => 'cb',\n
  3 => 'teststu',\n
  4 => 'cbteststu0567@students.xxx.ac.uk',\n
  5 => '',\n
  6 => 'oidc',\n
  7 => 'cbteststu0567@students.xxxx.ac.uk',\n
  8 => 1,\n
  9 => '192.168.xxx.xxx',\n
  10 => 1596099605,\n
  11 => 1596099605,\n
  12 => '1',\n
  13 => 'gregorian',\n
  14 => '2',\n
  15 => '1',\n
  16 => '0',\n
  17 => '1',\n
  18 => '0',\n
  )]\n
  Error code: dmlwriteexception\n
  * line 489 of /lib/dml/moodle_database.php: dml_write_exception thrown\n
  * line 1357 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()\n
  * line 1403 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()\n
  * line 111 of /user/lib.php: call to mysqli_native_moodle_database->insert_record()\n
  * line 4049 of /lib/moodlelib.php: call to user_create_user()\n
  * line 465 of /auth/oidc/classes/loginflow/authcode.php: call to create_user_record()\n
  * line 269 of /auth/oidc/classes/loginflow/authcode.php: call to auth_oidc\\loginflow\\authcode->handlelogin()\n
  * line 107 of /auth/oidc/classes/loginflow/authcode.php: call to auth_oidc\\loginflow\\authcode->handleauthresponse()\n
  * line 165 of /auth/oidc/auth.php: call to auth_oidc\\loginflow\\authcode->handleredirect()\n
  * line 29 of /auth/oidc/index.php: call to auth_plugin_oidc->handleredirect()\n, referer: https://login.microsoftonline.com/

I've taken a look out our site settings and it appears that the default country is set to UK


Any thoughts on what might be going wrong here?

Average of ratings: -
In reply to Conor Bradley

Re: OpenID error Field 'country' doesn't have a default value

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

It looks like mdl_user.country actually should have a default value, a blank string, so if you're seeing "Field 'country' doesn't have a default value" presumably there's an issue with the way that table was created. From my site the relevant line in SHOW CREATE TABLE mdl_user is (I have MariaDB 10.3.22):

  `country` varchar(2) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',

What does your database have for this?

I attach the complete SHOW CREATE TABLE output for reference.

Average of ratings: Useful (1)
In reply to Leon Stringer

Re: OpenID error Field 'country' doesn't have a default value

by Conor Bradley -
Looking at my database I've got 

 `country` varchar(2) COLLATE utf8mb4_unicode_ci NOT NULL,


Complete SHOW CREATE TABLE output attached.


In reply to Conor Bradley

Re: OpenID error Field 'country' doesn't have a default value

by Conor Bradley -
Obviously missing the default of '' so I ran

ALTER TABLE mdl_user
ALTER Country SET DEFAULT '';

Which has resolved the issue for me - the OpenID Connect login button is able to create users successfully now.

Thank you for the steer in the right direction!