1

I had a Model called Media; it was since renamed to "PetImage" and further revised. Now ack doesn't find the string "Media" in any of my Python source files, .pyc files, my templates, or my SQLite3 database. So far as I can tell from re-examining source (and restarting Gunicorn), the string "Media" shouldn't be anywhere to be found anywhere in my project apart from e.g. stuff under CKeditor's root. I've also made and executed migrations.

But I'm still getting http://dpaste.com/0FX74SJ - Django is erroring out on a reported failure to load "Media":

Exception Value: 'module' object has no attribute 'Media'

What can I do so that Django doesn't expect the 'module' object (my models.py, I think) to provide a Media?

The function that appears to be getting the complaint is the fourth line, with the for loop, in:

def one_pet(request, pet_id):
    pet = models.Pet.objects.get(id = pet_id)
    media = []
    for item in models.PetImage.objects.all():
        if item.url.startswith('https://youtu.be/'):
            media.append('')
        else:
            media.append('')
    return render(request, 'one_pet.html', {
        'pet': pet,
        'site_name': settings.SITE_NAME,
        })

Is there additional bookkeeping to do if a model is renamed? What should I be doing if I want my now PetImage to be treated as the successor to Media and all further activity directed to PetImage?

Thanks,

Christos Hayward
  • 5,777
  • 17
  • 58
  • 113
  • If you can, I'd advise you to drop all your model's tables(directly in your db), go into the django.migrations table and delete anything related to your app, then delete the migrations folder of your app and do a clean migration. This sort of thing happened lof of times during the development of my application, and I had to do this procedure several times – Mojimi Mar 17 '17 at 20:09

1 Answers1

0

ack doesn't find the string "Media" in any of my Python source files, .pyc files

I don't think it would fine them in the .pyc files. Have you tried deleting all pyc files in the directory? If this comes up a lot, you can either set the PYTHONDONTWRITEBYTECODE environment variable or execute a recursive delete in a post-merge hook in your version control setup.

Community
  • 1
  • 1
Tom
  • 22,301
  • 5
  • 63
  • 96