FileNotFoundError at /login/ [Errno 2] No such file or directory: '/app/media/profile pics/photo_0cEQgDs.jpg'

i have develop a blog app. it runs fine on local host. but when i upload it to heroku & try to login in this error massage came up. now i am stuck. here are all my project file
https://github.com/coderbang1/Blog

It seems like you uploaded your localhost’s database, but not the media directory. Any of the FileField type model fields store a path to the file within MEDIA_ROOT in your settings. If that’s the case, then removing the values for those fields in your models on the deployed version should allow it to run.

However, you still have the issue that Heroku will not store and serve uploaded files as you may be expecting. See this Stack Overflow question and answer for more information as to why.. I’d suggest using django-storages for handling media files in remote environments.

sir i use postgres(free) from heroku. i collect my static files.in that case what should i do? i am very new…(If that’s the case, then removing the values for those fields in your models on the deployed version should allow it to run)…if you could demonstrate, that would be helpful.

Regarding removing values, you can open a shell and run the following:

ModelWithMediaField.objects.filter(
    media_field__isnull=False
).update(media_field=None)

Where ModelWithMediaField is any model that has a FileField or ImageField or some other similar field and media_field is the name of the field.

The thing you’ll need to understand is that Heroku doesn’t store user uploaded files. They need to be stored elsewhere. Most folks answer is AWS S3. django-storages allows for a few different options though as you can see in the documentation.

1 Like

sir i question though…should i import anything in shell?

You’ll need to import the models that you need to change. Or you can use django-extensions shell_plus command which attempts to import all the models as well as other common utilities at the start of your shell.

1 Like

in my case it would be- from django.models import media?

No, it’s definitely a custom model that you’ve written or a model on a third party package you’ve installed. Please open a shell and play around with this locally. The skill of debugging software is a vital skill to a developer. You can install ipython that would allow you to auto-complete and explore properties on instances.

now i get it. thank you sir.

1 Like

sir, follow-up
return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: NOT NULL constraint failed: users_profile.image