DatabaseError:没有这样的列错误 [英] DatabaseError: no such column error

查看:140
本文介绍了DatabaseError:没有这样的列错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个我想添加ImageField的模型,所以我输入
picture = models.ImageField(upload_to ='media / images')

So I have a model that I wanted to add ImageField to, so I typed in picture = models.ImageField(upload_to='media/images')

然后我运行syncdb并进入shell:

I then ran syncdb and went into the shell:

python2 manage.py syncdb
python2 manage.py shell

然后导入模型并尝试

"model".objects.get(pk=1)

我得到错误:

DatabaseError: no such column: people_people.picture

当我为模型运行manage.py sql时

When I run manage.py sql for the model

"picture" varchar(100) NOT NULL

在数据库中。

你们有什么解决方案?我不能删除数据库中的数据。

What solutions do you guys have? I can't delete the data in the database.

推荐答案

文档 syncdb 不会将列添加到现有的表,它只创建新表。

As noted in the documentation syncdb doesn't add columns to existing tables, it only creates new tables.

我建议运行

python manage.py sqlall <your_app>

查看正在更改的表输出的sql,然后运行

Looking at the sql it outputs for the table you're changing, and then running

python manage.py dbshell

以便手动发出 ALTER TABLE 命令。

将来,您可能希望使用一个迁移工具,如南部

In future, you might like to use a migration tool like South.

这篇关于DatabaseError:没有这样的列错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆