8

I'm new to the django world. Running some tutorial apps, and when running python manage.py test i'm getting a failure saying that the table already exists. I'm not sure what is going on. I am also running south, and I got no errors when migrating the schema.

Any insight is greatly appreciated.

TIA Joey

Joey Blake
  • 3,451
  • 2
  • 18
  • 16
  • Possibly related: http://stackoverflow.com/questions/3090648/django-south-table-already-exists – payne Feb 03 '11 at 03:31
  • YES! That was it, I made some mistakes and got migration out of sync with the db. clean installs fixed it right up. – Joey Blake Feb 06 '11 at 22:20

5 Answers5

15

It might be an error in one of your south migrations. You don't see the problem on the real db because the migration has been executed (with the--fake option maybe)

You can try to recreate the db from scracth and see if it works.

You can also disable South for unit-tests by adding SOUTH_TESTS_MIGRATE = False in your settings.py. With this option a regular syncdb will be done to create the test database. It will also speed the testing process.

I hope it helps

luc
  • 41,928
  • 25
  • 127
  • 172
3

This also happened to me with a legacy code but for another reason.

I had two models with db_table referencing the same db table. I know that is stupid, but it's not my fault )

And I never found anything on the internet that could help me. I was saved by verbosity set to 3 (manage.py test -v 3) Hope this helps anyone.

class Bla1(Model):
    some_column = ...
    class Meta:
        db_table = 'some_table'

class Bla2(Model):
    some_column = ...
    class Meta:
        db_table = 'some_table'
  • helped, fixed tracking which models are set to managed in a custom [TestRunner](https://dev.to/vergeev/testing-against-unmanaged-models-in-django) and keep `managed=False` in any model refrencing an already referenced table. – Evhz Jan 21 '20 at 19:19
0

This happens also with Nose when
--cover-package=userdata,incorrectname
One of package's name is incorrect

Bartosz Dabrowski
  • 1,850
  • 2
  • 15
  • 21
0

and if you are testing with nose:

DST_RUN_SOUTH_MIGRATIONS = False

allo
  • 3,955
  • 8
  • 40
  • 71
0

You have to similar models, check it

Muhammadalive
  • 648
  • 5
  • 5