在南方迁移后,我最终删除了一列。现在我的一个表中的当前数据搞砸了,我想删除它,但尝试删除只会导致错误:
>>> 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
>>>
有一种简单的方法可以强行删除吗?我是否删除该表,然后重新运行manage.py schemamigration以在南方重新创建表?
答案 0 :(得分:1)
您可以使用
python manage.py reset [YOUR APP NAME]
但它会删除该应用程序所有表格中的所有数据。
或者您可以运行普通的旧sql,删除该表并重新运行迁移
> mysql -p -h HOST -u USER DATABASE_NAME
>> DROP TABLE APPNAME_degree;
>> exit;
> python manage.py migrate