Bulk upload users error: Error Writing to Database

Bulk upload users error: Error Writing to Database

by Adeel Ahmad -
Number of replies: 6

Hi,

I am using Moodle 2.2.7 stable version. I want to upload users using CSV. I have created my CSV using info available on Moodle Documentation. When I upload CSV file it gives proper PREVIEW Window and then I click "upload users" button and it gives error as below:

Error writing to database

More information about this error

Debug info: Column 'data' cannot be null
INSERT INTO mdl_user_info_data (userid,fieldid,data) VALUES(?,?,?)
[array (
0 => 160,
1 => '1',
2 => NULL,
)]
Stack trace:
line 397 of /lib/dml/moodle_database.php: dml_write_exception thrown
line 973 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
line 1015 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
line 120 of /user/profile/lib.php: call to mysqli_native_moodle_database->insert_record()
line 429 of /user/profile/lib.php: call to profile_field_base->edit_save_data()
line 716 of /admin/tool/uploaduser/index.php: call to profile_save_data()

Kindly help!!

Average of ratings: -
In reply to Adeel Ahmad

Re: Bulk upload users error: Error Writing to Database

by Justin Filip -

Hi Adeel,

Did this CSV file contain a value for a "menu of choices" custom profile field? If so you have just hit a very, very old bug that has been around since Moodle 1.9.

There are more details in MDL-16764 if that is the case here.

In reply to Justin Filip

Re: Bulk upload users error: Error Writing to Database

by Adeel Ahmad -

Hi Justin,

Thanks for reply. My CSV doesnt contain any Custom Profile Filed. You can have a look on my CSV file. Please find attached file with this post. It contains only required fields and one course that I want them to enroll in. Also I have checked the same CSV with other moodle versions that is working fine.

In reply to Adeel Ahmad

Re: Bulk upload users error: Error Writing to Database

by Justin Filip -

Hi Abdeel,

Do you have any custom user profile fields that are defined as being required? If so, do any of those fields have an empty default value?

It looks like Moodle is probably trying to save an empty value for a required profile field when creating the user. If that's the case then you would either need to set a default value for required fields or specify values in your CSV import file.

In reply to Justin Filip

Re: Bulk upload users error: Error Writing to Database

by Justin Filip -

Hi Adeel,

Did my suggestions above resolve your problem?

In reply to Justin Filip

Re: Bulk upload users error: Error Writing to Database

by Adeel Ahmad -

Hello Justin,

My moodle doesn't have any custom fields also. It is a fresh install with default profile fields only. I just can't understand why it is showing error when everything is fine and according to rule.

In reply to Adeel Ahmad

Re: Bulk upload users error: Error Writing to Database

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

Hi Adeel,

When I tried this out, I made two changes to your file - I added a role field so that when the 'upload user' enrols the user to the course it knows what role to give them, I also converted it to comma separated rather than tab separated.

Unfotunately I did both without checking each change separately, so I cant tell you which made the difference, but with both those changes it worked. Hopefully though that will give you enough to narrow down and try it out.

Richard