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> 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+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/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/CAJxq849kDAk_y%3DHzq3KWtPsbMN-OQrinb-vW0L-nAMq3Z8ttsw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to