In solr search, solve the error: model 'X' has an empty model_attr 'company' and doesn't allow a default or null value
In solr search, solve the error: model 'X' has an empty model_attr 'company' and doesn't allow a default or null value
我在 Django 中使用 solr 搜索。当我用 Solr 重建索引时,出现以下错误:
model 'X' has an empty model_attr 'company' and doesn't allow a default or null value.
有谁知道我犯的错误,我该如何解决这个问题。
您需要将其添加为
indexes.CharField(model_attr='company', null=True)
如果你想允许空格,那么
添加blank=True
indexes.CharField(model_attr='company', blank=True, null=True)
您的数据库中似乎有一些条目的必填字段留空。这可能是由于向现有模型添加新的必填字段,导致模型的现有实例因字段为空而失效。
如果你想强制该字段有一个值,你需要给现有实例一个字段值。如果你使用迁移工具 south it will give you an interactive prompt to fix the problem. Check out the "Data Migration" section of the south documentation.
如果您可以将该字段保留为可选,请设置 blank=True
(允许将该字段留空)和 null=True
(为空字段设置 NULL)。
我在 Django 中使用 solr 搜索。当我用 Solr 重建索引时,出现以下错误:
model 'X' has an empty model_attr 'company' and doesn't allow a default or null value.
有谁知道我犯的错误,我该如何解决这个问题。
您需要将其添加为
indexes.CharField(model_attr='company', null=True)
如果你想允许空格,那么
添加blank=True
indexes.CharField(model_attr='company', blank=True, null=True)
您的数据库中似乎有一些条目的必填字段留空。这可能是由于向现有模型添加新的必填字段,导致模型的现有实例因字段为空而失效。
如果你想强制该字段有一个值,你需要给现有实例一个字段值。如果你使用迁移工具 south it will give you an interactive prompt to fix the problem. Check out the "Data Migration" section of the south documentation.
如果您可以将该字段保留为可选,请设置 blank=True
(允许将该字段留空)和 null=True
(为空字段设置 NULL)。