DEV Community

Testing against unmanaged models in Django

Pavel Vergeev on August 15, 2017

The problem My Django application is supposed to read the tables of an already existing database. So the models of the database are gene...
Collapse
 
nobism profile image
Martin Nobis • Edited

I've found that this only works when a migration is applied to your database when managed=True has been set for all of your models. In this case, we've fixed the problem of Django not being able to load fixtures into the database to run the tests. But what's the point of going through all this trouble when managed=True the whole time anyway?

Does this make sense or am I missing something?

Collapse
 
sdolemelipone profile image
Mark G

I found a much simpler method via Vitor's blog at simpleisbetterthancomplex.com/tips... If you put your unmanaged database models in a different app to your managed ones, you can set

MIGRATION_MODULES = {'my_unmanaged_app': None}

in settings.py. All the relevant tables and columns will be created for testing, but no migrations are necessary.

Collapse
 
enether profile image
Stanislav Kozlovski

Thanks for taking the time to collect and share this information!

Collapse
 
derekcrosson profile image
Derek Crosson

Hey, Paveel!

Do you have a link to the repo? I'm trying to figure out which files to put some of the code in.

Collapse
 
gpaw789 profile image
gpaw789

Good day Paul

What django version were you using for this?

I am currently on django 2.0.8 and both solutions did not work. I keep getting django.db.utils.OperationalError: no such table

thanks!

Collapse
 
josericardo profile image
José Ricardo

Thanks!

Collapse
 
thecal714 profile image
Sean Callaway

Just ran into this problem yesterday and wanted to thank you for the simple solution.