views:

121

answers:

1

After a migration with south, I ended up deleting a column. Now the current data in one of my tables is screwed up and I want to delete it, but attempts to delete just result in an error:

>>> d = Degree.objects.all()
>>> d.delete()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Python26\lib\site-packages\django\db\models\query.py", line 440, in d
elete
    for i, obj in izip(xrange(CHUNK_SIZE), del_itr):
  File "C:\Python26\lib\site-packages\django\db\models\query.py", line 106, in _
result_iter
    self._fill_cache()
  File "C:\Python26\lib\site-packages\django\db\models\query.py", line 760, in _
fill_cache
    self._result_cache.append(self._iter.next())
  File "C:\Python26\lib\site-packages\django\db\models\query.py", line 269, in i
terator
    for row in compiler.results_iter():
  File "C:\Python26\lib\site-packages\django\db\models\sql\compiler.py", line 67
2, in results_iter
    for rows in self.execute_sql(MULTI):
  File "C:\Python26\lib\site-packages\django\db\models\sql\compiler.py", line 72
7, in execute_sql
    cursor.execute(sql, params)
  File "C:\Python26\lib\site-packages\django\db\backends\util.py", line 15, in e
xecute
    return self.cursor.execute(sql, params)
  File "C:\Python26\lib\site-packages\django\db\backends\sqlite3\base.py", line
200, in execute
    return Database.Cursor.execute(self, query, params)
DatabaseError: no such column: students_degree.abbrev
>>>

Is there a simple way to just force a delete? Do I drop the table and then rerun manage.py schemamigration to recreate the table in south?

A: 

You could use

python manage.py reset [YOUR APP NAME]

but it would delete all the data from all the tables of that app.

Or you could run plain old sql, delete that table and rerun the migration

> mysql -p -h HOST -u USER DATABASE_NAME
>> DROP TABLE APPNAME_degree;
>> exit;
> python manage.py migrate
Guillaume Esquevin