django 的models 里面的有一个字段我改了。我在dbshell 里删除重新添加字段的时候出错

cndeer 2013-08-13 10:56:47
django 的models 里面的有一个字段我改了。我在dbshell 里删除重新添加字段的时候出错了。请看提示

我要添加一个新的字段
在python manage.py dbshell 里用这语句:
sqlite> begin;
sqlite> alter table depotapp_product add column phone_dh integer not null default 0;
sqlite> commit;

可以。但是我改了这个QQ的字段。准备删除重新添加的时候。发现用这语句删不了?

sqlite> begin;
sqlite> alter table depotapp_product drop column phone_dh integer not null default 0;
sqlite> commit;

出错提示如下:

...全文
260 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
panghuhu250 2013-08-29
  • 打赏
  • 举报
回复
copied from sqlite3 FAQ: (Assuming the old table has three columns a,b and c, and we want to drop column c):
BEGIN TRANSACTION;
CREATE TEMPORARY TABLE t1_backup(a,b);
INSERT INTO t1_backup SELECT a,b FROM t1;
DROP TABLE t1;
CREATE TABLE t1(a,b);
INSERT INTO t1 SELECT a,b FROM t1_backup;
DROP TABLE t1_backup;
COMMIT;
panghuhu250 2013-08-14
  • 打赏
  • 举报
回复
建新表,拷数据,去旧表,改表名。
cndeer 2013-08-14
  • 打赏
  • 举报
回复
那要是想删除一个字段。重新添加。怎么操作啊?
panghuhu250 2013-08-14
  • 打赏
  • 举报
回复
sqlite不支持drop column吧?只能add column或rename table。
cndeer 2013-08-14
  • 打赏
  • 举报
回复
建新表,拷数据,去旧表,改表名 这几个操作。分别用的哪几个操作指令?多谢
cndeer 2013-08-13
  • 打赏
  • 举报
回复
出错提示:Error: naer "drop": syntax error

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧