[Fixed]-In solr search, solve the error: model 'X' has an empty model_attr 'company' and doesn't allow a default or null value

0👍

You need to add it as

indexes.CharField(model_attr='company', null=True)

and if you want to allow the blank then

add blank=True

indexes.CharField(model_attr='company', blank=True, null=True)

1👍

It seems that you have some entries in your database where a mandatory field is left empty. This can be caused by adding a new mandatory field to an existing model so that existing instances of the model are invalidated due to the empty field.

If you want to enforce the field to have a value, you need to give the existing instances a value for the field. If you use the migration tool south it will give you an interactive prompt to fix the problem. Check out the “Data Migration” section of the south documentation.

If it is okay for you to leave the field optional, set blank=True (allows leaving the field blank) and null=True (sets NULL for empty field).

Leave a comment