from __future__ import unicode_literals

from django.db import migrations

def add_billing_address(apps, schema_editor):
    ''' Data migration add billing_address in Bill from user billing_address 
    field
    '''
    Bill = apps.get_model('billjobs', 'Bill')
    for bill in Bill.objects.all():
        bill.billing_address = bill.user.billing_address
        bill.save()

class Migration(migrations.Migration):

    dependencies = [
        ('billjobs', '0002_service_is_available_squashed_0005_bill_issuer_address_default'),
    ]

    operations = [
        migrations.RunPython(add_billing_address),
    ]

from __future__ import unicode_literals

from django.db import migrations, models

def add_billing_address(apps, schema_editor):
    ''' Data migration add billing_address in Bill from user billing_address 
    field
    '''
    Bill = apps.get_model('billjobs', 'Bill')
    for bill in Bill.objects.all():
        bill.billing_address = bill.user.userprofile.billing_address
        bill.save()

class Migration(migrations.Migration):

    dependencies = [
        ('billjobs', '0002_service_is_available_squashed_0005_bill_issuer_address_default'),
    ]

    operations = [
        migrations.AddField(
            model_name='bill',
            name='billing_address',
            field=models.CharField(max_length=1024),
        ),
        migrations.RunPython(add_billing_address),
    ]

Add billing_address and migrate data
Add billing_address and migrate data

  from __future__ import unicode_literals
  
- from django.db import migrations
+ from django.db import migrations, models
  
  def add_billing_address(apps, schema_editor):
      ''' Data migration add billing_address in Bill from user billing_address 
      field
      '''
      Bill = apps.get_model('billjobs', 'Bill')
      for bill in Bill.objects.all():
-         bill.billing_address = bill.user.billing_address
+         bill.billing_address = bill.user.userprofile.billing_address
          bill.save()
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('billjobs', '0002_service_is_available_squashed_0005_bill_issuer_address_default'),
      ]
  
      operations = [
+         migrations.AddField(
+             model_name='bill',
+             name='billing_address',
+             field=models.CharField(max_length=1024),
+         ),
          migrations.RunPython(add_billing_address),
      ]
  
Add billing_address and migrate data
## Code Before:
from __future__ import unicode_literals

from django.db import migrations

def add_billing_address(apps, schema_editor):
    ''' Data migration add billing_address in Bill from user billing_address 
    field
    '''
    Bill = apps.get_model('billjobs', 'Bill')
    for bill in Bill.objects.all():
        bill.billing_address = bill.user.billing_address
        bill.save()

class Migration(migrations.Migration):

    dependencies = [
        ('billjobs', '0002_service_is_available_squashed_0005_bill_issuer_address_default'),
    ]

    operations = [
        migrations.RunPython(add_billing_address),
    ]

## Instruction:
Add billing_address and migrate data
## Code After:
from __future__ import unicode_literals

from django.db import migrations, models

def add_billing_address(apps, schema_editor):
    ''' Data migration add billing_address in Bill from user billing_address 
    field
    '''
    Bill = apps.get_model('billjobs', 'Bill')
    for bill in Bill.objects.all():
        bill.billing_address = bill.user.userprofile.billing_address
        bill.save()

class Migration(migrations.Migration):

    dependencies = [
        ('billjobs', '0002_service_is_available_squashed_0005_bill_issuer_address_default'),
    ]

    operations = [
        migrations.AddField(
            model_name='bill',
            name='billing_address',
            field=models.CharField(max_length=1024),
        ),
        migrations.RunPython(add_billing_address),
    ]
