﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31301	bulk_create with ForeignKey fields with mixed filled/None values fails.	Hans Aarne Liblik	Hans Aarne Liblik	"I have a model with ForeignKey (null=True) to another model

{{{
class A(models.Model):
  name = models.CharField()

class B(models.Model):
  name = models.CharField()
  a = models.ForeignKey(A, on_delete=models.CASCADE, null=True)
}}}

When I try to use bulk_create as follows

{{{
B.objects.bulk_create([
  B(name='first', a_id=1)
  B(name='seconds', a_id=None)
])
}}}

the query fails with error

{{{
django.db.utils.DatabaseError: ORA-01790: expression must have same datatype as corresponding expression
}}}

I got bulk_create working if the ForeignKey references are either All None or All NOT None. It seems like the fix introduced in https://code.djangoproject.com/ticket/22669 fixes the case for NumberFields and CharFields, but ForeignKey field 'target_field' for me is 'AutoField' which is not defined in 
{{{
django/db/backends/oracle/utils.py#52  class BulkInsertMapper:
}}}
Manually editing that this file and adding 
{{{
class BulkInsertMapper:
  ...
  types: {
    ...
    ...
    'AutoField': NUMBER
  }
}}}

fixes the issue for me."	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed	oracle sql	Marti Raudsepp	Ready for checkin	1	0	0	0	1	0
