Django模型:删除字段 [英] Django Model: drop a field

查看:172
本文介绍了Django模型:删除字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有直接简单的方法从Django模型中删除字段?对于添加字段,migration可以完美运行,但不能删除,抛出以下错误

Is there a straightforward clean way to drop a field from Django model? for addition of a field, migrate works perfect but its not working for deletion throwing the following error


django.db.utils.DatabaseError:( 1060,重复的列名'xyz_json_old')

django.db.utils.DatabaseError: (1060, "Duplicate column name 'xyz_json_old'")


推荐答案

我正在使用南方,但仍然我必须在朋友的帮助下进行以下操作-

I am using south but still I had to go through the following with the help of my friend -

他说我一定已经搞砸了,南部的一些内部步骤不是原子性的

He says I must have botched up something and some internal steps in south are not atomic


  1. 编辑models.py文件并从类中删除列

  2. BASH PROMPT $ python manage.py schemamigration core --auto

  3. MYSQL PROMPT>更改表core_tablename放置列xyz_json_old;提交;

  4. BASH PROMPT $ python manage.py core

  1. edit the models.py file and delete the column from the class
  2. BASH PROMPT$ python manage.py schemamigration core --auto
  3. MYSQL PROMPT> alter table core_tablename drop column xyz_json_old; commit;
  4. BASH PROMPT$ python manage.py core

这篇关于Django模型:删除字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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