我在尝试使用Django的bulk_create方法插入数据时遇到以下错误。并不是所有的数据都被插入。在
(1054,“字段列表”中的“nan”列未知)
我不太明白“nan”是从哪里来的,因为我在这里明确声明了我的所有字段。在
我试图一次向数据库插入大量对象(大约10000个或更多)
我的代码如下,当观察是另一个对象时,使用的模型是时间测光法:
# With thanks to https://stackoverflow.com/questions/18383471/django-bulk-create-function-example for the
# example on how to use the bulk_create function so we don't thrash the DB
phot_objects = [
TemporaryPhotometry(
calibrated_magnitude=function_to_make_calibrated_magnitude(),
calibrated_error=uncertainty_stars[i],
magnitude_rms_error=mage_2[i],
x=x_2[i],
y=y_2[i],
alpha_j2000=ra_2[i],
delta_j2000=de_2[i],
fwhm_world=fwhm_2[i],
flags=flag_2[i],
magnitude=mag_2[i],
observation=observation,
)
for i in range(0, len(num_2))
]
TemporaryPhotometry.objects.bulk_create(phot_objects)
如果你能帮我解决这个问题,我将不胜感激。谢谢您。在
完整堆栈跟踪如下:
^{pr2}$
我通过用下面的if语句包装所有NumPy数组,比如
uncertainty_stars[i]
来检查它们是否为NaN,从而解决了这个问题。在uncertainty_stars[i] if not numpy.isnan(uncertainty_stars[i]) else None
相关问题 更多 >
编程相关推荐