ManyToManyField does not allow empty relations

2,672 views
Skip to first unread message

akonsu

unread,
Feb 17, 2007, 8:09:10 PM2/17/07
to Django users
Hello,

i have set A that has many-to-many relationship with set B

currently admin interface (at least) forces me to select at least one
object from B if i add an object to A and the other way around. i do
not want that. i want to add an object to A which has no related
objects in B.

i need to have a model that enables empty relations. is there a way to
achieve this?

thanks
konstantin

Malcolm Tredinnick

unread,
Feb 17, 2007, 8:15:24 PM2/17/07
to django...@googlegroups.com

You need to have specified null=True and blank=True on the
ManyToManyField in your model (and you need to have done that before you
created the database, otherwise it will not permit NULL values in that
column). If you do that, it should work fine.

Regards,
Malcolm


akonsu

unread,
Feb 18, 2007, 10:31:23 AM2/18/07
to Django users
thanks for your response.

specifying null=True for ManyToManyField will allow nulls in the
corresponding field in the association table, right? but since this
table is just a list of pairs this is not needed because having no
row at all has the same effect. correct? if so null=True is not
really necessary. or am i wrong?

konstantin

On Feb 17, 8:15 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:

Honza Král

unread,
Feb 18, 2007, 10:35:19 AM2/18/07
to django...@googlegroups.com
On 2/18/07, akonsu <ako...@gmail.com> wrote:
>
> thanks for your response.
>
> specifying null=True for ManyToManyField will allow nulls in the
> corresponding field in the association table, right? but since this
> table is just a list of pairs this is not needed because having no
> row at all has the same effect. correct? if so null=True is not
> really necessary. or am i wrong?

that is correct, null has no effect for ManyToMany Field

>
> konstantin
>
> On Feb 17, 8:15 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
> wrote:
> > On Sun, 2007-02-18 at 01:09 +0000, akonsu wrote:
> > > Hello,
> >
> > > i have set A that has many-to-many relationship with set B
> >
> > > currently admin interface (at least) forces me to select at least one
> > > object from B if i add an object to A and the other way around. i do
> > > not want that. i want to add an object to A which has no related
> > > objects in B.
> >
> > > i need to have a model that enables empty relations. is there a way to
> > > achieve this?
> >
> > You need to have specified null=True and blank=True on the
> > ManyToManyField in your model (and you need to have done that before you
> > created the database, otherwise it will not permit NULL values in that
> > column). If you do that, it should work fine.
> >
> > Regards,
> > Malcolm
>
>
> >
>


--
Honza Král
E-Mail: Honza...@gmail.com
ICQ#: 107471613
Phone: +420 606 678585

Reply all
Reply to author
Forward
0 new messages