Re: p.choice_set.all() error

2013-03-08 Thread Hugo Guzman
Thanks for the feedback. It's much appreciated.

On Thursday, March 7, 2013 10:39:42 PM UTC-5, Hugo Guzman wrote:
>
> Hey there. I'm working through Part I of the "Writing your first Django 
> app" tutorial and everything was going smoothly until I tried executing the 
> following command:
>
> >>> p.choice_set.all()
>
> When I try running it I get the proceeding errors (below). I've attached 
> my models.py file for context. Any help or guidance would be much 
> appreciated.
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File 
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/query.py", 
> line 72, in __repr__
> data = list(self[:REPR_OUTPUT_SIZE + 1])
>   File 
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/query.py", 
> line 87, in __len__
> self._result_cache.extend(self._iter)
>   File 
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/query.py", 
> line 291, in iterator
> for row in compiler.results_iter():
>   File 
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
>  
> line 763, in results_iter
> for rows in self.execute_sql(MULTI):
>   File 
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
>  
> line 818, in execute_sql
> cursor.execute(sql, params)
>   File 
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/backends/util.py", 
> line 40, in execute
> return self.cursor.execute(sql, params)
>   File 
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/backends/mysql/base.py",
>  
> line 114, in execute
> return self.cursor.execute(query, args)
>   File "/home/hugodev/dev/lib/python2.7/site-packages/MySQLdb/cursors.py", 
> line 201, in execute
> self.errorhandler(self, exc, value)
>   File 
> "/home/hugodev/dev/lib/python2.7/site-packages/MySQLdb/connections.py", 
> line 36, in defaulterrorhandler
> raise errorclass, errorvalue
> DatabaseError: (1054, "Unknown column 'polls_choice.choice_text' in 'field 
> list'")
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: p.choice_set.all() error

2013-03-08 Thread Tom Evans
On Fri, Mar 8, 2013 at 3:39 AM, Hugo Guzman  wrote:
> Hey there. I'm working through Part I of the "Writing your first Django app"
> tutorial and everything was going smoothly until I tried executing the
> following command:
>
 p.choice_set.all()
>
> When I try running it I get the proceeding errors (below). I've attached my
> models.py file for context. Any help or guidance would be much appreciated.
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/query.py",
> line 72, in __repr__
> data = list(self[:REPR_OUTPUT_SIZE + 1])
>   File
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/query.py",
> line 87, in __len__
> self._result_cache.extend(self._iter)
>   File
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/query.py",
> line 291, in iterator
> for row in compiler.results_iter():
>   File
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
> line 763, in results_iter
> for rows in self.execute_sql(MULTI):
>   File
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
> line 818, in execute_sql
> cursor.execute(sql, params)
>   File
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/backends/util.py",
> line 40, in execute
> return self.cursor.execute(sql, params)
>   File
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/backends/mysql/base.py",
> line 114, in execute
> return self.cursor.execute(query, args)
>   File "/home/hugodev/dev/lib/python2.7/site-packages/MySQLdb/cursors.py",
> line 201, in execute
> self.errorhandler(self, exc, value)
>   File
> "/home/hugodev/dev/lib/python2.7/site-packages/MySQLdb/connections.py", line
> 36, in defaulterrorhandler
> raise errorclass, errorvalue
> DatabaseError: (1054, "Unknown column 'polls_choice.choice_text' in 'field
> list'")

This means that the database table exists, but it is missing a field
that is in your models.py.

This normally means you have changed your model after you created the table.

Django cannot automatically modify your DB tables when you change your
models.py (although there are packages like django-south that help you
manage making the changes), so you need to either manually modify the
table, or remove the table and re-run 'python manage.py syncdb', which
will re-create it (without any data).

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: p.choice_set.all() error

2013-03-08 Thread Victor Rocha
The only thing I can think of it is that your database is not up-to-date 
with your models. You could drop the database and do a syncdb, otherwise 
using south to migrate your database schema could be an option.

Good luck,
Victor Rocha
RochApps 

On Thursday, March 7, 2013 10:39:42 PM UTC-5, Hugo Guzman wrote:
>
> Hey there. I'm working through Part I of the "Writing your first Django 
> app" tutorial and everything was going smoothly until I tried executing the 
> following command:
>
> >>> p.choice_set.all()
>
> When I try running it I get the proceeding errors (below). I've attached 
> my models.py file for context. Any help or guidance would be much 
> appreciated.
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File 
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/query.py", 
> line 72, in __repr__
> data = list(self[:REPR_OUTPUT_SIZE + 1])
>   File 
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/query.py", 
> line 87, in __len__
> self._result_cache.extend(self._iter)
>   File 
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/query.py", 
> line 291, in iterator
> for row in compiler.results_iter():
>   File 
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
>  
> line 763, in results_iter
> for rows in self.execute_sql(MULTI):
>   File 
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
>  
> line 818, in execute_sql
> cursor.execute(sql, params)
>   File 
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/backends/util.py", 
> line 40, in execute
> return self.cursor.execute(sql, params)
>   File 
> "/home/hugodev/dev/lib/python2.7/site-packages/django/db/backends/mysql/base.py",
>  
> line 114, in execute
> return self.cursor.execute(query, args)
>   File "/home/hugodev/dev/lib/python2.7/site-packages/MySQLdb/cursors.py", 
> line 201, in execute
> self.errorhandler(self, exc, value)
>   File 
> "/home/hugodev/dev/lib/python2.7/site-packages/MySQLdb/connections.py", 
> line 36, in defaulterrorhandler
> raise errorclass, errorvalue
> DatabaseError: (1054, "Unknown column 'polls_choice.choice_text' in 'field 
> list'")
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




p.choice_set.all() error

2013-03-08 Thread Hugo Guzman
Hey there. I'm working through Part I of the "Writing your first Django 
app" tutorial and everything was going smoothly until I tried executing the 
following command:

>>> p.choice_set.all()

When I try running it I get the proceeding errors (below). I've attached my 
models.py file for context. Any help or guidance would be much appreciated.

Traceback (most recent call last):
  File "", line 1, in 
  File 
"/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/query.py", 
line 72, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
  File 
"/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/query.py", 
line 87, in __len__
self._result_cache.extend(self._iter)
  File 
"/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/query.py", 
line 291, in iterator
for row in compiler.results_iter():
  File 
"/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
 
line 763, in results_iter
for rows in self.execute_sql(MULTI):
  File 
"/home/hugodev/dev/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
 
line 818, in execute_sql
cursor.execute(sql, params)
  File 
"/home/hugodev/dev/lib/python2.7/site-packages/django/db/backends/util.py", 
line 40, in execute
return self.cursor.execute(sql, params)
  File 
"/home/hugodev/dev/lib/python2.7/site-packages/django/db/backends/mysql/base.py",
 
line 114, in execute
return self.cursor.execute(query, args)
  File "/home/hugodev/dev/lib/python2.7/site-packages/MySQLdb/cursors.py", 
line 201, in execute
self.errorhandler(self, exc, value)
  File 
"/home/hugodev/dev/lib/python2.7/site-packages/MySQLdb/connections.py", 
line 36, in defaulterrorhandler
raise errorclass, errorvalue
DatabaseError: (1054, "Unknown column 'polls_choice.choice_text' in 'field 
list'")


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


from django.db import models

import datetime
from django.utils import timezone

# Create your models here.
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.question
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)


class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __unicode__(self):
return self.choice_text