No such column - Django











up vote
1
down vote

favorite
1












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)









share|improve this question




















  • 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















up vote
1
down vote

favorite
1












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)









share|improve this question




















  • 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













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





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)









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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












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






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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






    share|improve this answer

























      up vote
      0
      down vote













      Just pass pk=True in your foreingkey
      ex. user = models.ForeignKey(User,pk=True)
      this will solve the issue






      share|improve this answer























        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






        share|improve this answer












        Just pass pk=True in your foreingkey
        ex. user = models.ForeignKey(User,pk=True)
        this will solve the issue







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 9 at 3:29









        Arun

        61139




        61139






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Schultheiß

            Verwaltungsgliederung Dänemarks

            Liste der Kulturdenkmale in Wilsdruff