No such column - Django
up vote
1
down vote
favorite
My goal is to let users upload files to user-specific folders.
The error I get is
no such column: notendur_document.user_id
Here is the relevant part of my views.py
file. This is where the upload happens.
@login_required
def list(request):
# Handle file upload
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Document(docfile = request.FILES['docfile'])
newdoc.save()
# Redirect to the document list after POST
return HttpResponseRedirect(reverse('notendur.views.list'))
else:
form = DocumentForm() # An empty, unbound form
# Load documents for the list page
documents = Document.objects.all()
# Render list page with the documents and the form
return render_to_response(
'notendur/list.html',
{'documents': documents, 'form': form},
context_instance=RequestContext(request)
)
This is my models.py
file:
def _upload_path(instance,filename):
return instance.get_upload_path(filename)
class Document(models.Model):
docfile = models.FileField(upload_to=_upload_path)
user = models.ForeignKey(User)
def get_upload_path(self,filename):
return "media/uploads/"+str(self.user.id) + "/" + '%Y.%m.%d' + filename
According to the relevant .html
file, the error happens in the documents
variable in list()
.
register user method in views.py
:
def register_user(request):
if request.method == "POST":
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/accounts/register_success')
args = {}
args.update(csrf(request))
args['form'] = UserCreationForm()
return render_to_response('register.html', args)
python django
|
show 11 more comments
up vote
1
down vote
favorite
My goal is to let users upload files to user-specific folders.
The error I get is
no such column: notendur_document.user_id
Here is the relevant part of my views.py
file. This is where the upload happens.
@login_required
def list(request):
# Handle file upload
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Document(docfile = request.FILES['docfile'])
newdoc.save()
# Redirect to the document list after POST
return HttpResponseRedirect(reverse('notendur.views.list'))
else:
form = DocumentForm() # An empty, unbound form
# Load documents for the list page
documents = Document.objects.all()
# Render list page with the documents and the form
return render_to_response(
'notendur/list.html',
{'documents': documents, 'form': form},
context_instance=RequestContext(request)
)
This is my models.py
file:
def _upload_path(instance,filename):
return instance.get_upload_path(filename)
class Document(models.Model):
docfile = models.FileField(upload_to=_upload_path)
user = models.ForeignKey(User)
def get_upload_path(self,filename):
return "media/uploads/"+str(self.user.id) + "/" + '%Y.%m.%d' + filename
According to the relevant .html
file, the error happens in the documents
variable in list()
.
register user method in views.py
:
def register_user(request):
if request.method == "POST":
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/accounts/register_success')
args = {}
args.update(csrf(request))
args['form'] = UserCreationForm()
return render_to_response('register.html', args)
python django
2
You changed your model, but forgot to migrate (or syncdb in django<1.7 without South).
– Pavel Anossov
Jun 11 '14 at 14:35
I might be doing yet another thing wrong, but I get the same error. I just shut down the server, write python manage.py syncdb, and start the server again. Did I do that correctly?
– KSHMR
Jun 11 '14 at 14:36
Remove the database, create it again, and run syndb
– cor
Jun 11 '14 at 14:37
It still does not work, but I have one idea. I didn't create the user from the shell. I let the user register on the website itself. Could I have done something wrong there, resulting in this error? Perhaps created the user object incorrectly?
– KSHMR
Jun 11 '14 at 14:40
1
In the future, you might want to change the models when you already have some data you don't want to lose. You'll have to alter your tables manually then, which is annoying. Consider using South for schema migrations or upgrading to Django 1.7, which has them built-in.
– Pavel Anossov
Jun 11 '14 at 14:58
|
show 11 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
My goal is to let users upload files to user-specific folders.
The error I get is
no such column: notendur_document.user_id
Here is the relevant part of my views.py
file. This is where the upload happens.
@login_required
def list(request):
# Handle file upload
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Document(docfile = request.FILES['docfile'])
newdoc.save()
# Redirect to the document list after POST
return HttpResponseRedirect(reverse('notendur.views.list'))
else:
form = DocumentForm() # An empty, unbound form
# Load documents for the list page
documents = Document.objects.all()
# Render list page with the documents and the form
return render_to_response(
'notendur/list.html',
{'documents': documents, 'form': form},
context_instance=RequestContext(request)
)
This is my models.py
file:
def _upload_path(instance,filename):
return instance.get_upload_path(filename)
class Document(models.Model):
docfile = models.FileField(upload_to=_upload_path)
user = models.ForeignKey(User)
def get_upload_path(self,filename):
return "media/uploads/"+str(self.user.id) + "/" + '%Y.%m.%d' + filename
According to the relevant .html
file, the error happens in the documents
variable in list()
.
register user method in views.py
:
def register_user(request):
if request.method == "POST":
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/accounts/register_success')
args = {}
args.update(csrf(request))
args['form'] = UserCreationForm()
return render_to_response('register.html', args)
python django
My goal is to let users upload files to user-specific folders.
The error I get is
no such column: notendur_document.user_id
Here is the relevant part of my views.py
file. This is where the upload happens.
@login_required
def list(request):
# Handle file upload
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Document(docfile = request.FILES['docfile'])
newdoc.save()
# Redirect to the document list after POST
return HttpResponseRedirect(reverse('notendur.views.list'))
else:
form = DocumentForm() # An empty, unbound form
# Load documents for the list page
documents = Document.objects.all()
# Render list page with the documents and the form
return render_to_response(
'notendur/list.html',
{'documents': documents, 'form': form},
context_instance=RequestContext(request)
)
This is my models.py
file:
def _upload_path(instance,filename):
return instance.get_upload_path(filename)
class Document(models.Model):
docfile = models.FileField(upload_to=_upload_path)
user = models.ForeignKey(User)
def get_upload_path(self,filename):
return "media/uploads/"+str(self.user.id) + "/" + '%Y.%m.%d' + filename
According to the relevant .html
file, the error happens in the documents
variable in list()
.
register user method in views.py
:
def register_user(request):
if request.method == "POST":
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/accounts/register_success')
args = {}
args.update(csrf(request))
args['form'] = UserCreationForm()
return render_to_response('register.html', args)
python django
python django
edited Jun 11 '14 at 14:41
asked Jun 11 '14 at 14:33
KSHMR
383521
383521
2
You changed your model, but forgot to migrate (or syncdb in django<1.7 without South).
– Pavel Anossov
Jun 11 '14 at 14:35
I might be doing yet another thing wrong, but I get the same error. I just shut down the server, write python manage.py syncdb, and start the server again. Did I do that correctly?
– KSHMR
Jun 11 '14 at 14:36
Remove the database, create it again, and run syndb
– cor
Jun 11 '14 at 14:37
It still does not work, but I have one idea. I didn't create the user from the shell. I let the user register on the website itself. Could I have done something wrong there, resulting in this error? Perhaps created the user object incorrectly?
– KSHMR
Jun 11 '14 at 14:40
1
In the future, you might want to change the models when you already have some data you don't want to lose. You'll have to alter your tables manually then, which is annoying. Consider using South for schema migrations or upgrading to Django 1.7, which has them built-in.
– Pavel Anossov
Jun 11 '14 at 14:58
|
show 11 more comments
2
You changed your model, but forgot to migrate (or syncdb in django<1.7 without South).
– Pavel Anossov
Jun 11 '14 at 14:35
I might be doing yet another thing wrong, but I get the same error. I just shut down the server, write python manage.py syncdb, and start the server again. Did I do that correctly?
– KSHMR
Jun 11 '14 at 14:36
Remove the database, create it again, and run syndb
– cor
Jun 11 '14 at 14:37
It still does not work, but I have one idea. I didn't create the user from the shell. I let the user register on the website itself. Could I have done something wrong there, resulting in this error? Perhaps created the user object incorrectly?
– KSHMR
Jun 11 '14 at 14:40
1
In the future, you might want to change the models when you already have some data you don't want to lose. You'll have to alter your tables manually then, which is annoying. Consider using South for schema migrations or upgrading to Django 1.7, which has them built-in.
– Pavel Anossov
Jun 11 '14 at 14:58
2
2
You changed your model, but forgot to migrate (or syncdb in django<1.7 without South).
– Pavel Anossov
Jun 11 '14 at 14:35
You changed your model, but forgot to migrate (or syncdb in django<1.7 without South).
– Pavel Anossov
Jun 11 '14 at 14:35
I might be doing yet another thing wrong, but I get the same error. I just shut down the server, write python manage.py syncdb, and start the server again. Did I do that correctly?
– KSHMR
Jun 11 '14 at 14:36
I might be doing yet another thing wrong, but I get the same error. I just shut down the server, write python manage.py syncdb, and start the server again. Did I do that correctly?
– KSHMR
Jun 11 '14 at 14:36
Remove the database, create it again, and run syndb
– cor
Jun 11 '14 at 14:37
Remove the database, create it again, and run syndb
– cor
Jun 11 '14 at 14:37
It still does not work, but I have one idea. I didn't create the user from the shell. I let the user register on the website itself. Could I have done something wrong there, resulting in this error? Perhaps created the user object incorrectly?
– KSHMR
Jun 11 '14 at 14:40
It still does not work, but I have one idea. I didn't create the user from the shell. I let the user register on the website itself. Could I have done something wrong there, resulting in this error? Perhaps created the user object incorrectly?
– KSHMR
Jun 11 '14 at 14:40
1
1
In the future, you might want to change the models when you already have some data you don't want to lose. You'll have to alter your tables manually then, which is annoying. Consider using South for schema migrations or upgrading to Django 1.7, which has them built-in.
– Pavel Anossov
Jun 11 '14 at 14:58
In the future, you might want to change the models when you already have some data you don't want to lose. You'll have to alter your tables manually then, which is annoying. Consider using South for schema migrations or upgrading to Django 1.7, which has them built-in.
– Pavel Anossov
Jun 11 '14 at 14:58
|
show 11 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
Just pass pk=True in your foreingkey
ex. user = models.ForeignKey(User,pk=True)
this will solve the issue
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Just pass pk=True in your foreingkey
ex. user = models.ForeignKey(User,pk=True)
this will solve the issue
add a comment |
up vote
0
down vote
Just pass pk=True in your foreingkey
ex. user = models.ForeignKey(User,pk=True)
this will solve the issue
add a comment |
up vote
0
down vote
up vote
0
down vote
Just pass pk=True in your foreingkey
ex. user = models.ForeignKey(User,pk=True)
this will solve the issue
Just pass pk=True in your foreingkey
ex. user = models.ForeignKey(User,pk=True)
this will solve the issue
answered Nov 9 at 3:29
Arun
61139
61139
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24165669%2fno-such-column-django%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
You changed your model, but forgot to migrate (or syncdb in django<1.7 without South).
– Pavel Anossov
Jun 11 '14 at 14:35
I might be doing yet another thing wrong, but I get the same error. I just shut down the server, write python manage.py syncdb, and start the server again. Did I do that correctly?
– KSHMR
Jun 11 '14 at 14:36
Remove the database, create it again, and run syndb
– cor
Jun 11 '14 at 14:37
It still does not work, but I have one idea. I didn't create the user from the shell. I let the user register on the website itself. Could I have done something wrong there, resulting in this error? Perhaps created the user object incorrectly?
– KSHMR
Jun 11 '14 at 14:40
1
In the future, you might want to change the models when you already have some data you don't want to lose. You'll have to alter your tables manually then, which is annoying. Consider using South for schema migrations or upgrading to Django 1.7, which has them built-in.
– Pavel Anossov
Jun 11 '14 at 14:58