This is coming off the top of my head, but is this a case where the
ApplicationRequirements needs to be saved before you can add it to
another object? The exception is familiar and from memory means that
the instance lacks a primary key value (which it gets when it's
saved).

This *might* fix things:

requirement.save()
vacancy.save()   # may need this too to ensure both have pks
vacancy.application_requirements.add(requirement)

Again, all off the top of my head, and I'd probably need to see more
code to guess better :)

mick

On Mon, Jun 9, 2008 at 15:33, Daniel Kersten <[EMAIL PROTECTED]> wrote:
>
> PS: vacancy.pk is None for some reason... I don't really understand
> why, since the generated SQL specifies a primary key and my code was
> modeled after the sample code snippets in the django documentation.
>
> 2008/6/9 Daniel Kersten <[EMAIL PROTECTED]>:
>> Hi again,
>>
>> I'm having a few more problems with my django code. I am trying to add
>> entries to a models.ManyToManyField but it's not working.
>>
>> The exception thrown is:
>> <class 'apps.main.models.ApplicationRequirements'> instance needs to
>> have a primary key value before a many-to-many relationship can be
>> used.
>>
>> The code which raises this exception is:
>> vacancy.application_requirements.add(requirement)
>>
>> The definition of application_requirements in the vacancy model is:
>> application_requirements    =
>> models.ManyToManyField(ApplicationRequirements, editable=False)
>>
>> I checked the database, and both tables definitely have primary keys
>> (and besides, if I don't add one myself, django adds the 'id' field as
>> a primary key).
>> I'm not really sure whats causing the error or what I can do to fix it.
>>
>> Any tips would be greatly appreciated!
>> Dan.
>>
>> --
>> Daniel Kersten.
>> Leveraging dynamic paradigms since the synergies of 1985.
>>
>
>
>
> --
> Daniel Kersten.
> Leveraging dynamic paradigms since the synergies of 1985.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Python Ireland" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.ie/group/pythonireland?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to