Search code examples
djangodjango-tests

Can´t create test database django


I´m trying to test a django application, but when I run python manager.py test I got this error

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

it´s occurs in

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

In this point, billing_branch_launcher doesn't really exist, it´s create in migration 27

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'),
    ),

The migration 8 looks like this

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)]

How can I fix it?


Solution

  • I suggest install the python library

    django-test-without-migrations

    Then the migrations file errors don't affect to the tests.

    pip install django-test-without-migrations
    

    add it in INSTALLED_APPS (settings.py)

    Then run :

    python manage.py test --nomigrations

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