﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34793	Django ORM returns None when field has value in BD	Alexandre Rodrigues Batista	nobody	"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),
        ),
    ]
}}}

"	Bug	closed	Database layer (models, ORM)	3.2	Normal	invalid			Unreviewed	0	0	0	0	0	0
