I had a pre-existing model Item
. I added a ForeignKey(User) to this model recently and now I am getting no such column: todo_item.user_id
when I try to render pages.
Model:
class Item(models.Model):
user = models.ForeignKey(User) # new
name = models.CharField(max_length=60)
created = models.DateTimeField(auto_now_add=True)
priority = models.IntegerField(default=0)
difficulty = models.IntegerField(default=0)
done = models.BooleanField(default=False)
output from manage.py sqlall
:
BEGIN;
CREATE TABLE "todo_item" (
"id" integer NOT NULL PRIMARY KEY,
"user_id" integer NOT NULL REFERENCES "auth_user" ("id"),
"name" varchar(60) NOT NULL,
"created" datetime NOT NULL,
"priority" integer NOT NULL,
"difficulty" integer NOT NULL,
"done" bool NOT NULL
)
;
CREATE INDEX "todo_item_6340c63c" ON "todo_item" ("user_id");
COMMIT;
I realize that manage.py syncdb
will not alter my pre-existing table. And I understand that I could use South or something like it to avoid losing my data, but I am still in testing mode, and I don't care about any of the current data in my table. I am fine with wiping it clean to get this working. In fact I already have.
I've run:
python manage.py flush todo
and then
python manage.py syncdb
Which seems like it should've worked. After I ran flush it had me enter a new admin user, and all of my todo_item data is gone. But it doesn't seem to have killed the todo_item tables. After running these commands if I use PRAGMA table_info(todo_item)
inside sqlite shell I don't see the user_id column listed.
My question is: beyond flush
and syncdb
what do I have to do in order to get the database to reflect changes to my model?