开发者

Connecting object instance to user in django

开发者 https://www.devze.com 2023-03-15 18:21 出处:网络
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

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
0

精彩评论

暂无评论...
验证码 换一张
取 消