from django.db import migrations

app = 'model_logging'
model = 'LogEntry'


def move_data(apps, schema_editor):
    LogEntry = apps.get_model(app, model)
    for entry in LogEntry.objects.all():
        entry.data_temp = entry.data
        entry.save()

class Migration(migrations.Migration):

    dependencies = [
        ('model_logging', '0002_add_new_data_field'),
    ]

    operations = [
        migrations.RunPython(move_data),
    ]

from django.db import migrations

app = 'model_logging'
model = 'LogEntry'


def move_data(apps, schema_editor):
    try:
        from pgcrypto.fields import TextPGPPublicKeyField
    except ImportError:
        raise ImportError('Please install django-pgcrypto-fields to perform migration')

    LogEntry = apps.get_model(app, model)
    for entry in LogEntry.objects.all():
        entry.data_temp = entry.data
        entry.save()

class Migration(migrations.Migration):

    dependencies = [
        ('model_logging', '0002_add_new_data_field'),
    ]

    operations = [
        migrations.RunPython(move_data),
    ]

Add try, catch statement to ensure data migration can be performed.
Add try, catch statement to ensure data migration can be performed.

  from django.db import migrations
  
  app = 'model_logging'
  model = 'LogEntry'
  
  
  def move_data(apps, schema_editor):
+     try:
+         from pgcrypto.fields import TextPGPPublicKeyField
+     except ImportError:
+         raise ImportError('Please install django-pgcrypto-fields to perform migration')
+ 
      LogEntry = apps.get_model(app, model)
      for entry in LogEntry.objects.all():
          entry.data_temp = entry.data
          entry.save()
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('model_logging', '0002_add_new_data_field'),
      ]
  
      operations = [
          migrations.RunPython(move_data),
      ]
  
Add try, catch statement to ensure data migration can be performed.
## Code Before:
from django.db import migrations

app = 'model_logging'
model = 'LogEntry'


def move_data(apps, schema_editor):
    LogEntry = apps.get_model(app, model)
    for entry in LogEntry.objects.all():
        entry.data_temp = entry.data
        entry.save()

class Migration(migrations.Migration):

    dependencies = [
        ('model_logging', '0002_add_new_data_field'),
    ]

    operations = [
        migrations.RunPython(move_data),
    ]

## Instruction:
Add try, catch statement to ensure data migration can be performed.
## Code After:
from django.db import migrations

app = 'model_logging'
model = 'LogEntry'


def move_data(apps, schema_editor):
    try:
        from pgcrypto.fields import TextPGPPublicKeyField
    except ImportError:
        raise ImportError('Please install django-pgcrypto-fields to perform migration')

    LogEntry = apps.get_model(app, model)
    for entry in LogEntry.objects.all():
        entry.data_temp = entry.data
        entry.save()

class Migration(migrations.Migration):

    dependencies = [
        ('model_logging', '0002_add_new_data_field'),
    ]

    operations = [
        migrations.RunPython(move_data),
    ]
