python - fixture 加载失败 : DoesNotExist: . .. 匹配查询不存在

标签 python django fixtures

从 git 仓库运行 Django 1.5.x。使用 south 来管理迁移。我有一个这样的模型:

class Company(models.Model):
    name = models.CharField(max_length = 100)
    subdomain = models.CharField(max_length = 50)
    is_active = models.BooleanField(default=True)
    prefs = models.TextField(max_length=8*1024, null=True, blank=True, default=None)

    is_dev = models.BooleanField(default=False) # this is a development company - internal to 15Five

    trial_start_date = models.DateField(null=True, blank=True, default=None)
    trial_length_days = models.PositiveIntegerField(default = 28)

    email_domain = models.CharField(max_length = 100, null=True, blank=True, default=None)
    cohort = models.ForeignKey(Cohort, null=True, blank=True, default=None)

    create_ts = models.DateTimeField(_('Created'), default=timezone.now)
    update_ts = models.DateTimeField(_('Updated'), default=timezone.now)
    deactivate_ts = models.DateTimeField(_('Deactivated'), null=True, blank=True, default=None)
    converted_to_paying_ts = models.DateTimeField(_('Converted'), null=True, blank=True, default=None)

    features = models.ManyToManyField(Feature,
                                      verbose_name=_('feature'), blank=True,
                                      help_text='A feature which can be turned on or off for a company')

我在 django 管理中创建了一家公司。我使用 manage.py dumpdata ff.company --indent=2 导出一个 JSON fixture:

[
{
  "pk": 1,
  "model": "ff.company",
  "fields": {
    "cohort": null,
    "subdomain": "zzz",
    "name": "zzz",
    "trial_start_date": null,
    "trial_length_days": 0,
    "converted_to_paying_ts": "2012-12-02T11:06:10Z",
    "is_active": true,
    "update_ts": "2012-12-02T11:06:11Z",
    "is_dev": true,
    "deactivate_ts": null,
    "create_ts": "2012-12-02T11:05:56Z",
    "email_domain": "zzz.com",
    "prefs": "",
    "features": []
  }
}
]

我清除了我的 ff_company 表并运行我的迁移,但我收到一个错误:

Error in migration: ff:0004_create_default_companies
DoesNotExist: Problem installing fixture 'C:\<redacted>/migrations/fixtures/create_default_companies.json': Company matching query does not exist. Lookup parameters were {'id': 1}

知道问题出在哪里吗?我认为南方不是问题,因为如果我手动加载 fixture ,我也会收到错误:

>manage.py loaddata ..\migrations\fixtures\create_default_companies.json
DoesNotExist: Problem installing fixture 'C:\<redacted>\migrations\fixtures\create_default_companies.json': Company matching query does not exist. Lookup parameters were {'id': 1}

最佳答案

我的 Company 模型上有 pre_save 和 post_save 信号触发器。这些不是检查 raw 参数,而是试图对不存在的数据库值做一些聪明的事情。

关于python - fixture 加载失败 : DoesNotExist: . .. 匹配查询不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13668728/

相关文章:

python - 套接字未连接Python

python - 根据 numpy 数组的值更改其各个元素

具有特定数据的 Django 装置

python - 如何在 django 请求工厂发布请求中设置 request.body?

Swift 包管理器,如何处理固定装置?

testing - 是否可以将 ember 数据 fixture 适配器与单个对象而不是数组一起使用?

python - 如何在同一个Python程序中将Python变量传递给bash代码?

python - 将捕获的视频帧(numpy 数组对象)从网络摄像头传递到 caffe 模型

python - 带参数的 Django ManyToManyField 过滤器?

python - Django REST框架: error when testing POST request with list