Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7615999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:46:57+00:00 2026-05-31T02:46:57+00:00

This is the model I am using: class Comment(MPTTModel): comment = models.CharField(max_length=1023) resource =

  • 0

This is the model I am using:

class Comment(MPTTModel):
    comment = models.CharField(max_length=1023)
    resource = models.ForeignKey('Resource')
    created_at = models.DateTimeField(auto_now_add=True)
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
    author = models.ForeignKey(User)

    class MPTTMeta:
        order_insertion_by = ['created_at']

However, when I try to add a comment from the admin site I get:

ValueError at /admin/app/comment/add/
Cannot use None as a query value

Am I doing something wrong with my model? I feel like django-mptt is trying to get the DateTimeField while it is still “None”, before it has been set at the db level.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:47:00+00:00Added an answer on May 31, 2026 at 2:47 am

    No, you’re not doing something wrong. This is a bug in django-mptt.

    Basically datetime fields with auto_add_now=True don’t get a value until after django-mptt tries to figure out where to insert your model in the tree.

    I’ve just created an issue on django-mptt to fix this: https://github.com/django-mptt/django-mptt/issues/175

    In the meantime, you can work around this by proactively setting the value yourself. Get rid of the auto_now_add=True, and set the value in an overridden save() method on your model::

    from datetime import datetime
    
    class Comment(MPTTModel):
        comment = models.CharField(max_length=1023)
        resource = models.ForeignKey('Resource')
        created_at = models.DateTimeField()
        parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
        author = models.ForeignKey(User)
    
        class MPTTMeta:
            order_insertion_by = ['created_at']
    
        def save(self, *args, **kwargs):
            if not self.created_at:
                self.created_at = datetime.now()
            super(Comment, self).save(*args, **kwargs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following model. class Comment(models.Model): type = models.CharField(max_length=21, choices=OBJECT_TYPE_CHOICES) program = models.ForeignKey(Program, db_column='object_id',
I have this model and modelform: class Comment(models.Model): text = models.CharField(max_length=100) def clean_text(self): print
I have this model in django: class JournalsGeneral(models.Model): jid = models.AutoField(primary_key=True) code = models.CharField(Code,
Here two of my model classes: class DashboardVersion(models.Model): name = models.CharField(_(Dashboard name),max_length=100) description =
I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A
I have a model that looks something like this: class Comment < ActiveRecord::Base ...
I'm using FluentNHibernate but NHibernate XML will do. Say I have this model public
I am trying to automap my domain model using fluent nhibernate. In this particular
I am using custom model binder in ASP.NET MVC 2 that looks like this:
Is this the only way to create custom model validation? To do it using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.