Changes between Initial Version and Version 3 of Ticket #29367


Ignore:
Timestamp:
Apr 27, 2018, 12:56:35 PM (7 years ago)
Author:
Oscar Esgalha
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #29367

    • Property Owner changed from nobody to Oscar Esgalha
    • Property Status newassigned
  • Ticket #29367 – Description

    initial v3  
    3030
    3131
    32 class Analist(models.Model):
     32class Analyst(models.Model):
    3333    ext_id = models.CharField(primary_key=True, max_length=32)
    3434    groups = models.ManyToManyField(Group)
     
    3737group_aaa = Group.objects.get(ext_id='AAA')
    3838
    39 analist_eee = Analist(ext_id='EEE')
    40 Analist.objects.bulk_create([analist_eee])
     39analyst_eee = Analyst(ext_id='EEE')
     40Analyst.objects.bulk_create([analyst_eee])
    4141
    42 analist_eee.groups.set([group_aaa])  # ValueError: Cannot add "<Group: AAA>": instance is on database "None", value is on database "default"
     42analyst_eee.groups.set([group_aaa])  # ValueError: Cannot add "<Group: AAA>": instance is on database "None", value is on database "default"
    4343}}}
    4444
     
    4747A current workaround option is to manually set the `._state.db` after the bulk_create:
    4848{{{
    49  analist_eee = Analist(ext_id='EEE')
    50 Analist.objects.bulk_create([analist_eee])
    51 analist_eee._state.db = 'default'
     49 analyst_eee = Analyst(ext_id='EEE')
     50Analyst.objects.bulk_create([analyst_eee])
     51analyst_eee._state.db = 'default'
    5252
    53 analist_eee.groups.set([group_aaa]) # And now it works
     53analyst_eee.groups.set([group_aaa]) # And now it works
    5454}}}
Back to Top