2012-06-09 85 views
2

我有一个简单的迁移,看起来像这样:为什么South试图删除我想添加的列?

class Migration(SchemaMigration): 

    def forwards(self, orm): 
     db.add_column('activities_newsitem', 'related_story', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['projects.Story'], null=True, blank=True),keep_default=True) 

不幸的是,它没有,我不知道为什么。以下是输出。注意,它运行添加列查询就好了。事实上,当我查看数据库时,该列正确无误。

但由于某种原因,它后来运行了一个drop列,这就是失败。为什么这样做?

DEBUG south execute "ALTER TABLE `activities_newsitem` ADD COLUMN `related_story_id` integer NULL;" with params "[]" (generic.py:145) 
DEBUG south execute "ALTER TABLE `activities_newsitem` ADD CONSTRAINT `related_story_id_refs_id_3d3841088db0fdb0` FOREIGN KEY (`related_story_id`) REFERENCES `projects_story` (`id`);" with params "[]" (generic.py:145) 
DEBUG south execute "CREATE INDEX `activities_newsitem_related_story_id` ON `activities_newsitem` (`related_story_id`);" with params "[]" (generic.py:145) 
DEBUG south execute "ALTER TABLE `activities_newsitem` ADD COLUMN `related_story_id` integer NULL;" with params "[]" (generic.py:145) 
DEBUG south execute "ALTER TABLE `activities_newsitem` ADD CONSTRAINT `related_story_id_refs_id_3d3841088db0fdb0` FOREIGN KEY (`related_story_id`) REFERENCES `projects_story` (`id`);" with params "[]" (generic.py:145) 
DEBUG south execute "ALTER TABLE `activities_newsitem` DROP COLUMN `related_story_id` CASCADE;" with params "[]" (generic.py:145) 
! Error found during real run of migration! Aborting. 

! Since you have a database that does not support running 
! schema-altering statements in transactions, we have had 
! to leave it in an interim state between migrations. 

感谢所有帮助

+0

两次运行相同的语句吗?这可能以某种方式触发回滚尝试?我不知道...... GL! –

回答

1

它看起来像它试图两次运行命令。如果你查看你的迁移文件夹,你是否有2个迁移?如果您在不实际迁移的情况下运行create migration命令两次,它可能会这样做。

您是否偶然运行过您的命令两次? 您可以通过打开数据库控制台并检查您的迁移是否位于south_migrationhistory表中来检查此情况。

假设你使用的是unixy系统(OSX/Linux的),在命令行:

mysql -u username -p password

然后

select * from south_migrationhistory;

是您的移民在那里呢?

如果是这样你的任务完成了,你可以继续前进。如果不是,并且您的activities_newsitem表具有该列,则需要伪造迁移以使您的南迁移历史记录保持最新。

假冒迁移:

python manage.py migrate activities --fake 0001

,其中0001是迁移数(所有迁移文件都带有前缀号码)。

相关问题