django South 正在更改 init 上的布尔数据

发布于 2024-12-24 19:26:07 字数 1014 浏览 4 评论 0原文

要将我的数据库输出到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

趴在窗边数星星i 2024-12-31 19:26:07

schemamigrationmigrate --fake 不会修改数据库。您是否有可以在迁移时重新加载的初始数据固定装置?请参阅 https://docs.djangoproject.com/en/1.3/howto/initial -data/

尝试迁移:

python manage.py migrate --no-initial-data

请参阅 south doc有关选项的更多信息

schemamigration and migrate --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:

python manage.py migrate --no-initial-data

see south doc for more info about options

A君 2024-12-31 19:26:07

我认为 --initial 或 --fake 根本不应该改变数据库,所以我很惊讶它会修改数据。至于您收到“未同步(使用迁移)”错误的原因,我认为这可能是因为您伪造了初始迁移。

尝试取消迁移 --fake 并重新应用初始迁移 然后

python manage.py migrate --fake zero
python manage.py migrate

,您应该能够执行 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

python manage.py migrate --fake zero
python manage.py migrate

Then, you should be able to do the dumptdata

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文