Changing the name of 'date' did not fix the issue. 

I have ended up changing the database field from DATETIME to TEXTFIELD. Not 
a good fix, but since there seems to be no clear solution to this I went 
ahead. It works at least. 

I have tried the Q-based queries too, by the way. (And other ways of saying 
the same thing. The problem definitely doesn't lie in the queries).

Den måndagen den 7:e juli 2014 kl. 01:14:52 UTC+2 skrev Russell Keith-Magee:
>
> Date isn't *disallowed* as a field name: 
>
>
> http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html#table-reserved-words-new-5.5
>
> As long as it's quoted, it's an allowed name.
>
> However, it's *really* not recommended.
>
> This isn't for database related reasons - it's the Python side that is 
> problematic. The name of the class used to *store* date objects is also 
> named "date". As a result, you're going to get all sorts of unpredictable 
> namespace conflicts, because at various times in the same module, "date" 
> will be either a class or a model field. Unless you're *very* careful about 
> imports and how you use them, you're going to trip over unexpected 
> behaviours.
>
> This is probably something we should add to the model warning suite; if 
> someone is looking for an project to get involved with Django, this would 
> be a relatively easy feature to add.
>
> Yours,
> Russ Magee %-)
>
>
>
>
> On Sun, Jul 6, 2014 at 10:51 AM, Dean <dean...@gmail.com <javascript:>> 
> wrote:
>
>> I think there is a restriction in using 'date' in MySQL as a field name 
>> as it's some sort of inbuilt function. 
>>
>> On Friday, July 4, 2014 5:01:15 PM UTC+8, William Granli wrote:
>>>
>>> I am trying to create a queryset for getting the values of a 
>>> DateTimeField which is DATETIME in the DB.
>>>
>>> The class in models.py:
>>>
>>> class ChangeMetrics(models.Model):
>>>     id = models.IntegerField(primary_key=True)
>>>     file_id = models.ForeignKey(File, db_column = 'file_id')
>>>     version_id = models.ForeignKey(Version, db_column = 'version_id')
>>>     function_id = models.ForeignKey(Function, blank=True, db_column = 
>>> 'function_id')
>>>     date = models.DateTimeField(blank=True, null=True)
>>>     user = models.TextField(blank=True)
>>>     changed = models.IntegerField(blank=True, null=True)
>>>
>>> The field in the SQL DB:
>>>
>>> date DATETIME
>>>
>>> The tuples are populated in the database and running SQL queries 
>>> directly on the DB is working perfectly.
>>>
>>> This is the queryset I am currently using in Django:
>>>
>>> queryset = ChangeMetrics.objects.filter(~Q(changed=None), ~Q(date=None), 
>>> ~Q(version_id=None))
>>>
>>> I have tried a raw query and also a version of the query that uses 
>>> exclude(), but that still returns None for date.
>>>
>>> I am accessing the entries in the queryset through a for loop and simply 
>>> accessing date through entry.date inside the for loop.
>>>
>>> I am using Django version 1.6.5. I have also tried getting the values 
>>> through the Django shell, to no success.
>>>
>>> Any ideas on what could be wrong? I have tried a multitude of queries, 
>>> none of them change the returned value of date. I have tried resyncing the 
>>> DB. I've looked over the models and everything seems to be correct. 
>>> Everything except the date works fine.
>>>
>>  -- 
>> 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...@googlegroups.com <javascript:>.
>> To post to this group, send email to django...@googlegroups.com 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/20994464-f99b-40bf-a16e-aaff87ff9d5a%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/20994464-f99b-40bf-a16e-aaff87ff9d5a%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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+unsubscr...@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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5b0166b3-d22c-49a9-9b09-ff8290498aa9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to