I have a simple model and I want to save it using the ModelForm.
Here's the code:
#models.py
class MyArchive(models.Model):
archive_id = models.CharField(max_length = 20, primary_key=True)
description = models.CharField(max_length = 50, blank = True)
archive_file = models.FileField(upload_to = "my_archives/")
#views.py
class MyArchiveForm(ModelForm):
class Meta:
model = MyArchive
def upload(request):
if request.method == 'POST':
form = MyArchiveForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return HttpResponse('uploaded success!')
else:
logger.debug("invalid form")
return HttpResponse('upload fail!')
I've synced DB and saw the tables created. But every time it goes to form.save then says
DatabaseError, no such table.
Is my way to save using ModelForm wrong?
UPDATE:
What's even weird that when I removed this line: form.save()
, it fails at if form.is_valid()
with the same error no such table
, but when I run django in debug mode, if form.is_valid()
works fine.