Unknown column error when I add a field

68 views
Skip to first unread message

Tool69

unread,
Sep 20, 2006, 5:39:40 AM9/20/06
to Django users
Hi,
I'm totally new to django, I've made a little blog application and my
original template is like this one:

class News(models.Model):
title = models.CharField(maxlength=255, verbose_name="Titre du
billet")
text = models.TextField(verbose_name="Contenu")
keywords = models.CharField(maxlength=255, verbose_name="Mots
clés")
date = models.DateTimeField(verbose_name="Date de publication")
etc.

All is getting well but now (runnin it with MySQL on WebFaction), I
wanted to stick an image with each post, so I added that field to my
News class :

post_image = models.ImageField(upload_to='entetes/', blank=True,
help_text="Doit etre de 300px de large")

But now, I received an error message saying :
(1054, "Unknown column 'news_news.supplementary_image' in 'field
list'")

What's going wrong ?
Thanks a lot :
6TooL9

Andy Dustman

unread,
Sep 25, 2006, 11:08:10 AM9/25/06
to django...@googlegroups.com

You'll need to hand-update your table schema. If you run:

./manage.py sql appname

it willl print the new schema. Then you can run:

./manage.py dbshell

and then do:

alter table news.news add [new column definition goes here];

Alternatively, you can dump that table, DROP it, use manage.py syncdb
to re-create it, and then reload the dumped table (minus schema). I
usually use alter table.

I think there are plans to have Django modify existing schemas when
the models change, but it's not implemented yet.
--
This message has been scanned for memes and
dangerous content by MindScanner, and is
believed to be unclean.

James Bennett

unread,
Sep 25, 2006, 11:08:18 AM9/25/06
to django...@googlegroups.com
On 9/20/06, Tool69 <kibleur.c...@gmail.com> wrote:
> But now, I received an error message saying :
> (1054, "Unknown column 'news_news.supplementary_image' in 'field
> list'")

When you change your model, you also have to make changes to your
database to correspond. Django does not currently offer any automatic
facility for this, so you will need to manually write and execute the
appropriate ALTER TABLE statement(s).

--
"May the forces of evil become confused on the way to your house."
-- George Carlin

James Punteney

unread,
Sep 25, 2006, 11:08:28 AM9/25/06
to django...@googlegroups.com
When you add a new field to a model you currently have to manually add
the field to the database as well.

With webfaction this is easiest to do by using the MysqlAdmin through
their control panel. If you aren't sure what type of field it needs to
be you can run the manage.py sql to get an output of the create table
statements from which you can determine the type of field and other
parameters.

--James


On 9/20/06, Tool69 <kibleur.c...@gmail.com> wrote:
>

Tool69

unread,
Sep 25, 2006, 1:25:59 PM9/25/06
to Django users
Thanks to all,
I'm sorry for the late, but I cannot see my post before.
I solved the problem with your help,
see you,
6TooL9

Reply all
Reply to author
Forward
0 new messages