I'm currently working on my first Django project and have hit a roadblock in regard to adding an ImageField to an existing model.
I currently have a model for a user posting content and one for django-profiles. For the former, I added an ImageField so the used can submit a photo to accompany the text content. For the latter, I want to allow users to upload a profile photo (not worried at the moment about avatar resizing).
Things were working well until I added ImageFields to both models. I then synced the database with South. What resulted when I try to pull up the once working templates for profiles is:
"no such column: report_userprofile.profile_pic"
A similar error occurs when trying to view the submitted text content.
I set both of the fields to "blank=True" so it seemed as if not having an image file would not cause an error. I'm obviously wrong.
I did not initially put these fields in the models, which in hindsight was a big mistake. I've also just set up the MEDIA_ROOT and MEDIA_URL as follows:
MEDIA_ROOT = 'os.path.join(BASE_DIR, "media")'
MEDIA_URL = 'http://localhost:8000/media'
The models I'm now using are:
class Story(models.Model):
title = models.CharField(max_length=100)
topic = models.CharField(max_length=50)
copy = models.TextField()
author = models.ForeignKey(User)
zip_code = models.CharField(max_length=10)
latitude = models.FloatField(blank=False, null=False)
longitude = models.FloatField(blank=False, null=False)
date = models.DateTimeField(auto_now=True, auto_now_add=True)
pic = models.ImageField(upload_to='pictures', blank=True)
def __unicode__(self):
return " %s" % (self.title)
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
first_name = models.CharField(max_length=25)
last_name = models.CharField(max_length=35)
email = models.EmailField()
birth_date = models.DateField(blank=True, null=True)
city = models.CharField(max_length=25)
state = models.CharField(max_length=20)
zip_code = models.CharField(max_length=10)
profile_pic = models.ImageField(upload_to='pictures', blank=True)
The URLs file is set up as follows:
url(r'^admin/', include(admin.site.urls)),
(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT},
The core problem here is I have no idea what the error might be (the previous templates even?). Or better yet, errors, as I'm sure I've made several. It's a bit of a soup right now along with the resulting distress.
Just as an FYI, I have installed the PIL.
Any insight at all, even small insight, into what I need to do to remedy this situation would be beyond appreciated. I've searched for similar issues but none this specific emerges. (The first lesson for the future would be to obviously set up the ImageFiles when initially assembling the models.)
Many thanks.