django South 正在更改 init 上的布尔数据
要将我的数据库输出到 json 文件,我通常会这样做
python manage.py dumptdata --indent=4 > mydata.json
但是,在执行以下两个命令来设置 South 时:
python manage.py schemamigration myproj --initial
python manage.py migrate myproj --fake
我注意到 mytable 中条目的两个布尔值从 FALSE 切换为 TRUE!我从与数据库交互的 GUI Web 界面中看到,但是为了更仔细地比较更改和损坏的内容,我想将 json 与 json 进行比较,但启用了 South 后,我不能再使用上面的命令,因为它告诉我
Not synced (use migrations):
- myproj
我的表如果下面的条目受到影响,我可能会有更多我尚未发现的受影响数据。
class MyConfig(models.Model):
name = models.CharField(max_length=64)
myConfigName = models.CharField(max_length=64, unique=True)
myA = models.ForeignKey(MyA)
myB = models.ForeignKey(MyB)
myBoolA = models.BooleanField()
myBoolB = models.BooleanField()
myBoolC = models.BooleanField()
class Meta:
unique_together = ('name', 'myA', 'myB')
def __unicode__(self):
return '%s_%s_%s' % (self.myA.name, self.myB.name, self.name)
To output my database to json file I would usually do
python manage.py dumptdata --indent=4 > mydata.json
However upon executing the following two commands to setup south:
python manage.py schemamigration myproj --initial
python manage.py migrate myproj --fake
I noticed that two of my booleans in mytable for an entry were switched from FALSE to TRUE! I see that from my GUI Web Interface interacting with the database however to more closely compare what changed and got corrupted I'd like to compare json to json but with south enabled I can no longer use the above command as it tells me
Not synced (use migrations):
- myproj
My table that had entries affected is below, I could have more affected data that I have not uncovered.
class MyConfig(models.Model):
name = models.CharField(max_length=64)
myConfigName = models.CharField(max_length=64, unique=True)
myA = models.ForeignKey(MyA)
myB = models.ForeignKey(MyB)
myBoolA = models.BooleanField()
myBoolB = models.BooleanField()
myBoolC = models.BooleanField()
class Meta:
unique_together = ('name', 'myA', 'myB')
def __unicode__(self):
return '%s_%s_%s' % (self.myA.name, self.myB.name, self.name)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
schemamigration
和migrate --fake
不会修改数据库。您是否有可以在迁移时重新加载的初始数据固定装置?请参阅 https://docs.djangoproject.com/en/1.3/howto/initial -data/尝试迁移:
请参阅 south doc有关选项的更多信息
schemamigration
andmigrate --fake
don't modify the database. Do you have any initial_data fixture that could be reloaded when migrating? See https://docs.djangoproject.com/en/1.3/howto/initial-data/Try to migrate with:
see south doc for more info about options
我认为 --initial 或 --fake 根本不应该改变数据库,所以我很惊讶它会修改数据。至于您收到“未同步(使用迁移)”错误的原因,我认为这可能是因为您伪造了初始迁移。
尝试取消迁移 --fake 并重新应用初始迁移 然后
,您应该能够执行 dumptdata
I don't think that either an --initial or a --fake should alter the database at all, so I'm surprised that it would modify data. In terms of why you're getting the "Not synced (use migrations)" error, I think it's likely because you faked the initial migration.
Try un-migrating the --fake and re-applying the initial migration with
Then, you should be able to do the dumptdata