【发布时间】:2012-03-02 08:34:44
【问题描述】:
关于 Django 和 Python:
错误:
异常类型:DatabaseError 异常值:
列 objects_thing.name_id 不存在 第 1 行:...s_thing"."created", "objects_thing"."modified", "objects...
在我的 manage.py sql 对象中
CREATE TABLE "objects_thing" (
otherstuff,
otherstuff,
"name_id" integer NOT NULL REFERENCES "profiles_name" ("id"),
otherstuff,
);
所以它显然存在。 我已经运行了syncdb。 为什么我会收到此错误?我该如何修复它? (我是这一切的新手)提前感谢您的帮助。
编辑:
事物模型:
class Thing(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
name = models.ForeignKey(Name)#The name for this thing
current_allocation = models.DecimalField(max_digits=13, decimal_places=2, null=True, blank=True)
target_allocation = models.DecimalField(max_digits=13, decimal_places=2, null=True, blank=True)
placeholder = models.ForeignKey(Entity, null=True, blank=True, on_delete=models.SET_NULL)
avatar = models.ImageField(upload_to='avatars/thing/', null=True, blank=True)
【问题讨论】:
-
如果你在这里显示你的代码会更好
-
编辑,添加模型。不知道你还需要什么。
-
不,我的意思是您检索数据库的代码。此外,您应该删除当前的对象数据库并手动创建它
-
python manage.py sql objectspython manage.py dbshell atler table objects_thing add column "name_id" integer REFERENCES "profiles_name" ("id")