I’m trying to create an app where all data belongs to exactly one user, and users only axcess their own data (e.g. email). I model this in my models.py file like so:
from django.contrib.auth.models import User
from django.db import models
...
class Foo(models.Model):
owner=ForeignKey(User, related_name='foos')
which seems to work fine.
python manage.py sql appFoo
displays sql including
CREATE TABLE "appFoo_foo" (
"id" integer NOT NULL PRIMARY KEY,
"owner_id" integer NOT NULL REFERENCES "auth_user" ("id")
...
The problem, though, arises when I try to delete users I have created for testing purposes, both using
User.objects.exclude(username='root').delete()
and using the built-in django admin app. In either case I get a database error saying that the table appFoo_foo has no column named owner_id. This is after running syncdb. Any thoughts as to why this might happen?
I swear I looked for related questions before asking this one, but I didn’t see Database error : no such column: connect_connect.reciever_id until after I asked it. My problem was the same. Basically, I added a field to my model and expected syncdb to modify the database accordingly, but apparently it doesn’t. I had to run
followed by syncdb again, and it worked like a charm.
Edit: I’m just now reading that reset is deprecated and you can use flush instead.