root777

I have several tables as below, which was created according

Oct 9th, 2018
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | None | 0 0
  1. """I have several tables as below, which was created according to a `third-party system`, application also runs under the database of this system(oracle).
  2.  
  3. Constraint failed in `Table `A, but it works in `Table B`, supposed I want to display e.name in `Table B` with code of `b.c.d.e.name`, the fronted page displayed exact data, and fronted page displayed `None` in `Table A` with code of `a.b.c.d.e.name`,
  4. """
  5.     class A(models.Model):
  6.         a_id = models.IntegerField(primary_key=True)
  7.         b = models.OneToOneField('B', models.DO_NOTHING, related_name='+')
  8.    
  9.     class B(models.Model):
  10.         b_id = models.IntegerField(primary_key=True)
  11.         c = models.OneToOneField('C', models.DO_NOTHING, related_name='+')
  12.    
  13.     class C(models.Model):
  14.         c_id = models.IntegerField(primary_key=True)
  15.         d = models.OneToOneField('D', models.DO_NOTHING, related_name='+')
  16.    
  17.     class D(models.Model):
  18.         d_id = models.IntegerField(primary_key=True)
  19.         e = models.OneToOneField('E', models.DO_NOTHING, related_name='+')
  20.  
  21.     class E(models.Model):
  22.         e_id = models.IntegerField(primary_key=True)
  23.         name = models.CharField(max_length=64)
  24.  
  25.  
  26. # Results of pdb as below:
  27.  
  28.     (Pdb) B.objects.using('third_party_db').get(c__d__e__name="Dog")
  29.     *** general.models.B.MultipleObjectsReturned: get() returned more than one B -- it returned 1673!
  30.     (Pdb) A.objects.using('third_party_db').get(b__c__d__e__name="Dog")
  31.     *** general.models.A.DoesNotExist: A matching query does not exist.
  32.     (Pdb) A.objects.using('third_party_db').get(b__c__pk=1)
  33.     *** general.models.A.DoesNotExist: A matching query does not exist.
  34.     (Pdb) A.objects.using('third_party_db').get(b__f__pk=1)
  35.     *** general.models.A.MultipleObjectsReturned: get() returned more than one A -- it returned 18!
Advertisement
Add Comment
Please, Sign In to add comment