new_contents: # -*- coding: utf-8 -*-
  # Generated by Django 1.11.15 on 2018-11-12 18:55
  from __future__ import unicode_literals
  
  from django.db import migrations, models
  
  
  def delete_tm_entries(apps, schema):
      """
      Delete TranslationMemoryEntries that are linked to existing Entity instances
      and aren't linked to any Translation instances.
  
      See bug 1506167 for more details.
      """
      TranslationMemoryEntry = apps.get_model('base', 'TranslationMemoryEntry')
  
      TranslationMemoryEntry.objects.filter(
          translation__isnull=True,
          entity__isnull=False,
      ).delete()
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('base', '0136_android_strings_xml'),
      ]
  
      operations = [
          migrations.RunPython(
              delete_tm_entries,
              migrations.RunPython.noop,
          ),
      ]
  
subject: Fix bug 1506167: Remove TM entries of deleted Translations (#1129)