2

When I start my app it works perfectly, but when I try to run a testcase it creates the test DB from my local copy and errors for a missing column that I can see in my local DB and was part of an older migrations.

Any suggestions

(venv) PS C:\Users\mtmcd\Azure Devops\Blindspot> python manage.py runserver 127.0.0.1:8888
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
May 19, 2022 - 11:02:25
Django version 3.0.8, using settings 'blindspot.settings'
Starting development server at http://127.0.0.1:8888/
Quit the server with CTRL-BREAK.
[19/May/2022 11:02:48] "GET /endpoints/list HTTP/1.1" 200 82572

But when I run python manage.py test I get

(venv) PS C:\Users\mtmcd\Azure Devops\Blindspot> python manage.py test
Creating test database for alias 'default'...
Traceback (most recent call last):
  File "C:\Users\mtmcd\Azure Devops\Blindspot\venv\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedColumn: column agents_simulationaction.alert_test_name does not exist
LINE 1: ...d", "agents_simulationaction"."security_tool_id", "agents_si...
Michael McDermott
  • 344
  • 3
  • 6
  • 14
  • there are two options: 1) u are still referring to that column inside the code or more probably, 2) the migration is broken, which means that u didn't follow the best patterns for creating the migration files. To make a test, just let Django refer to a new db and try to apply the migrations from scratch and let us know if it works – Mattia May 19 '22 at 15:46
  • First, Delete the test DB and then try again. If that not works your migrations are broken. Then you need to roll back migrations and overwrite the broken one. – Erik Kalkoken May 19 '22 at 16:41

1 Answers1

0

I was able to get this working by doing the following.

Deleting all migrations, doing a makemigrations, deleting the entries in the django_migrations table, then migrate --fake on the main DB. This allowed the test DB to create successfully

Michael McDermott
  • 344
  • 3
  • 6
  • 14