Field type 'None' not recognized for registration extension field 'company'

I’ve added a custom fields to registration page. They have been added successfully with one issue. I’ve a foreign key field ‘company’ in the model. Adding this create following exception:

ImproperlyConfigured at /register
Field type 'None' not recognized for registration extension field 'city'.
Request Method:	GET
Request URL:	http://localhost:18000/register
Django Version:	2.2.16
Exception Type:	ImproperlyConfigured
Exception Value:	
Field type 'None' not recognized for registration extension field 'city'.
Exception Location:	/edx/app/edxapp/edx-platform/openedx/core/djangoapps/user_authn/views/registration_form.py in get_registration_form, line 399
Python Executable:	/edx/app/edxapp/venvs/edxapp/bin/python

The following exception is created because foreign key field by default uses ModelChoiceField which is not included in FIELD_TYPE_MAP in /edx-platform/openedx/core/djangoapps/user_api/helpers.py
If we add this, this might resolve the issue but is there any other solution without changing the core files?

Hi @Javeria_Ejaz,

Thanks for the details in your question. I took a quick look and I don’t think you’re missing anything. You’ll need to either (A) use a different field type that’s already supported, or (B) update FIELD_TYPE_MAP in /edx-platform/openedx/core/djangoapps/user_api/helpers.py to add support for ModelChoiceField.

You are also right that a bit of additional work may be required, but it’s hard to say unless you try it.

If you choose to go with option (B) and submit a pull request to make that change to the platform, I’d be happy to review it and merge it for you.