#34793: Django ORM returns None when field has value in BD
-------------------------------------+-------------------------------------
               Reporter:  Alexandre  |          Owner:  nobody
  Rodrigues Batista                  |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  3.2
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 I have this model:
 {{{
 class Issue(models.Model):
     is_active = models.BooleanField(default=True)
     issue_id = models.IntegerField()
     new_issue_id = models.IntegerField(null=True)
     issue_name = models.CharField(max_length=50)
     periodic = models.ForeignKey(to=Periodic, on_delete=models.SET_NULL,
 null=True)
     app = models.IntegerField(default=1)

     def __str__(self) -> str:
         return f'{self.issue_name} - {self.new_issue_id}'
 }}}


 and always I try to get field "new_issue_id", Django returns "None" to me
 My db values

 {{{
 INSERT INTO public.issue_issue
 (is_active,issue_id,issue_name,periodic_id,app,new_issue_id) VALUES
          (true,13,'Issue A',18,1,13),
          (true,12,'Issue B',19,1,12)

 }}}

 Issue.objects.raw_sql got same result as Issue.objets.all or
 Issue.objets.find or Issue.objets.get...


 My solution was to use psycopg2 directly.

 I checked Django_migrations table, and migration was there


 {{{
 class Migration(migrations.Migration):

     dependencies = [
         ('issue', '0002_issue_issue_app'),
     ]

     operations = [
         migrations.AddField(
             model_name='issue',
             name='new_issue_id',
             field=models.IntegerField(null=True),
         ),
     ]
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34793>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018a206aec52-818d41d2-7040-44f5-bbc1-0330192333df-000000%40eu-central-1.amazonses.com.

Reply via email to