无法创建测试数据库 django



我正在尝试测试一个django应用程序,但是当我运行python manager.py测试时,我得到了这个错误

django.db.utils.ProgrammingError: column deals_dealproposal.billing_branch_launcher_id does not exist

它出现在

File "/migrations/0008_dynamicpackingtype.py", line 18, in run
for proposal in bulk_proposals:

在这里,billing_branch_launcher实际上并不存在,它是在迁移中创建的。

migrations.AddField(
model_name='dealproposal',
name='billing_branch_launcher',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='billing_branch_launcher', to='clients.CoffeeCompany'),
),

迁移8看起来像这样

class Migration(migrations.Migration):
dependencies = [
('coffeedeals', '0007_auto_20190315_1642'),
('schemas', '0003_dynamicpackingtype')
]
def run(app, schema_editor):
bulk_proposals = md.DealProposal.active.filter(
data__negotiation__packing='bulk',
data__negotiation__packing_type__isnull=False)
for proposal in bulk_proposals:
del proposal.data['negotiation']['packing_type']
proposal.save()
operations = [migrations.RunPython(run, atomic=True)]

我该如何修复它?

我建议安装python库

django-test-without-migrations

那么迁移文件错误就不会影响到测试。

pip install django-test-without-migrations

添加到INSTALLED_APPS (settings.py)

然后运行:

python manage.py test --nomigrations

参考:https://pypi.org/project/django-test-without-migrations/

最新更新