Django M2M with Oracle database FieldDoesNotExist error

59 views
Skip to first unread message

mohse...@gmail.com

unread,
Aug 3, 2015, 6:18:47 AM8/3/15
to Django users
Hello Django community.

I have two Django models Foo and Bar that have a  ManyToMany relation:

Class Foo(models.model):
  ...
  bars = models.ManyToManyField('Bar', related_name='foos')

somewhere in the code, i do direct assignment to replace the relation with a new list:

foo_object.bars = [bar_object_list]

but i get:

FieldDoesNotExist: Foo_bars has no field named None

I use Django 1.8.3 with Oracle 12c

any help would be highly appreciated

Erik Cederstrand

unread,
Aug 3, 2015, 6:31:28 AM8/3/15
to Django Users

> Den 03/08/2015 kl. 08.50 skrev mohse...@gmail.com:
>
> Hello Django community.
> I have two Django models Foo and Bar that have a ManyToMany relation:
>
> Class Foo(models.model):
>
> ...
>
> bars = models.ManyToManyField('Bar', related_name='foos')
> somewhere in the code, i do direct assignment to replace the relation with a new list:
>
> foo_object.bars = [bar_object_list]

You can't do that, AFAIK. You need to do:

foo_object.bars.clear()
foo_object.bars.add(*bar_object_list)


Erik

mohse...@gmail.com

unread,
Aug 3, 2015, 11:45:42 PM8/3/15
to Django users
Erik, as stated in documentation, what you said is equivalent to what i did
and the error exists yet. to have more details, here is the stack trace:

Traceback (most recent call last):
 
File "<console>", line 2, in <module>
 
File "/home/user/Workspace/src/models.py", line 155, in create_from_dict
    obj
.bars.clear()
 
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py", line 1253, in __get__
    through
=self.field.rel.through,
 
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py", line 862, in __init__
    source_field
= through._meta.get_field(source_field_name)
 
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 554, in get_field
   
raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, field_name))

FieldDoesNotExist: Foo_bars has no field named None

mohse...@gmail.com

unread,
Aug 4, 2015, 1:16:12 AM8/4/15
to Django users
i found that even trying to access the relation (i.e. foo.bars) will trigger the same error !!!
the only special thing about my model is that i defined foo's primary key as BigIntegerField

Felipe Horta

unread,
Jun 10, 2016, 12:39:36 PM6/10/16
to Django users
Hi everyone, I'm following this thread and I'm having the same error. Im running a postgis db, and despite the biginteger pk, my problem is the same. Could you solve it?

Thanks!
Reply all
Reply to author
Forward
0 new messages