I am trying to use models.ForeignKey('User')
to connect my model to the auth user in django. But when I try to submit my form to cre开发者_运维知识库ate a new object instance the form won't validate and I get the error ... has no column named user_id
. Is there some other way I am suppose to be connecting my objects to the auth.User or is more information needed to answer this question?
EDIT:
sqlall gives:
BEGIN;
CREATE TABLE "checker_check" (
"id" integer NOT NULL PRIMARY KEY,
"title" varchar(80) NOT NULL,
"user_id" integer NOT NULL REFERENCES "auth_user" ("id"),
"video" varchar(200) NOT NULL,
"text" text NOT NULL
)
;
CREATE INDEX "checker_check_fbfc09f1" ON "checker_check" ("user_id");
COMMIT;
Did you add the Foreign Key field after the table was created? If so you'll have to add that manually. If you don't care about losing the data in your db then this should work:
python manage.py reset app_name
If you do need to keep the data the following sql statement should work:
ALTER TABLE table_name ADD COLUMN user_id integer
精彩评论