Opened 15 months ago
Closed 15 months ago
#34793 closed Bug (invalid)
Django ORM returns None when field has value in BD
Reported by: | Alexandre Rodrigues Batista | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 3.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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), ), ]
Note:
See TracTickets
for help on using tickets.
TBH, I'm not sure what you're trying to report, but it looks like a support question and Trac is not a support channel. If you're having trouble understanding how Django works, see TicketClosingReasons/UseSupportChannels for ways to get help.