[CentralOH] (Django) ValueError: 'Book' instance needs to have a primary key value before a many-to-many relationship can be used.
kurtis.mullins at gmail.com
Wed Oct 24 18:28:38 CEST 2012
If you don't get it figured out, feel free to share some code and I can
probably give you a point in the right direction.
On Wed, Oct 24, 2012 at 11:11 AM, Kurtis Mullins
<kurtis.mullins at gmail.com>wrote:
> Sorry, I should have been more clear. I believe you only need one save()
> before you call add() on the m2m field. I don't think you need to call it
> again afterwards.
> And yeah, you can call save with commit=False to get an object instance
> but I don't believe you will have a primary key until it's committed
> I could be wrong though :) my brain has been all over the place
> coding-wise lately.
> On Oct 24, 2012 11:06 AM, <jep200404 at columbus.rr.com> wrote:
>> On Wed, 24 Oct 2012 10:37:30 -0400, Kurtis Mullins <
>> kurtis.mullins at gmail.com> wrote:
>> > You should only need 1 save. The .add() doesn't require a save if memory
>> > serves me correctly.
>> I am dealing with a newly created object/row that does not yet
>> have a primary key (id) until the first save.
>> How were you getting a value for the primary key for the .add()
>> to use? Were you using an object/row that already existed and so
>> had already been saved earlier?
>> On Wed, 24 Oct 2012 10:29:03 -0400, jep200404 at columbus.rr.com wrote:
>> > by doing a .save() to flesh out the primary key value,
>> > then doing the .add() for the ManyToManyField,
>> > then doing another .save().
>> I might have discovered a solution. I see something now that
>> I did not see when I first looked at the code.
>> Add commit=False to the first save.
>>  busi = business.save(commit=False)
>> from the last answer of
>> CentralOH mailing list
>> CentralOH at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the CentralOH