Models inside tests - Django 1.7 problem

42 views
Skip to first unread message

galgal

unread,
Sep 4, 2014, 11:03:23 AM9/4/14
to django...@googlegroups.com
Hi,
I'm trying to port my project to use Django 1.7. Everything is fine except 1 thing. Models inside tests folders.
Django 1.7 new migrations run migrate  command internally. Before syncdb was ran. That means if a model is not included in migrations - it won't be populated to DB (and also to test DB). That's exactly what I'm experiencing right now.

What I do is:
  • In my /app/tests/models.py I have dummy model: class TestBaseImage(BaseImage): pass
  • All it does is to inherit from an abstract BaseImage model.
  • Then in tests I create instances of that dummy model to test it.
The problem is that it doesn't work any more. It's not included in migrations (that's obvious as I don't want to keep my test code in production DB). Running my tests causes DB error saying that table does not exist. That makes sense as it's not included in migrations.

Is there any way to make it work with new migrations system? I can't find a way to "fix" that.

Benjamin Scherrey

unread,
Sep 5, 2014, 4:28:50 AM9/5/14
to django-users
I'm not sure what the specific issue with migrations is but this article has a nice trick (intended for making temporary models/tables) that would allow you to bring in a model and get it to sync whenever you like. I'd suggest putting this in your test setUp() method. It uses 'syncdb' cause it's pre-1.7 but you could try it with 'migrate' and see if that works as well. I haven't tried this for a long time so please post your results/workarounds if you manage to incorporate it in your solution.


-- Ben


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2236bfb7-7676-4caf-a6b1-9438ec5bba93%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Chief Systems Architect Proteus Technologies
Personal blog where I am not your demographic.

This email intended solely for those who have received it. If you have received this email by accident - well lucky you!!
Reply all
Reply to author
Forward
0 new messages