Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Model: drop a field

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, "Duplicate column name 'xyz_json_old'")

like image 708
comiventor Avatar asked Oct 28 '25 01:10

comiventor


1 Answers

If you want to drop only the field from the model try this

$ python manage.py dbshell 

You will get directly within your database shell (mysql or psql) it up to what database you are using.

$ mysql> | psql> ALTER TABLE <table_name> DROP column <COLUMN_NAME>;

Open the model too (the python file)and take off the field name from the model and type now

$ python manage.py syncdb

And it will drop the column to from table, doesn't matter if the table is already populated or not.

like image 175
drabo2005 Avatar answered Oct 30 '25 17:10

drabo2005