Tuesday, July 16, 2013

Re: Mysterious WHERE clause when updating an object

On Mon, Jul 15, 2013 at 3:05 PM, J. Barber <jbarber@iliff.edu> wrote:
> I am having trouble updating an existing table using django on ms sql
> server. Here is the query I am using:
>
>>>> c = Candidacy.objects.get(id_num=610020956, stage__in=('150 ', '350
>>>> '))
>>>> c.enroll_dep_amt = 146
>>>> c.save()
>
> But the SQL query sent to the server does not look as it should. Instead, I
> get this (note especially the WHERE clause):
>
>>>> print connection.queries[-1]
> {'time': '0.079', 'sql': u'UPDATE [CANDIDACY] SET [CUR_CANDIDACY] = Y,
> [STAGE] =
> 150 , [ENROLL_FEE_TYPE] = help?, [ENROLL_DEP_DTE] = 2013-07-15 13:12:01,
> [enro
> ll_dep_amt] = 146 WHERE [CANDIDACY].[YR_CDE] = 2013 '}
>
> Thus, instead of updating a single row, the sql updates over 1000 rows.
> Below is my model:
>
> class Candidacy(models.Model):
> id_num = models.IntegerField(primary_key=True, db_column=u"ID_NUM")
> trm_cde = models.CharField(max_length=2, primary_key=True,

^^^^^^^^^^^
> db_column=u"TRM_CDE")
> yr_cde = models.CharField(max_length=4, primary_key=True,

^^^^^^^^^^^

Don't have multiple primary keys.

Cheers

Tom

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate