On Sat, Apr 11, 2009 at 5:53 AM, Poromenos <porome...@gmail.com> wrote: > > Hello, > I created a model that has a ForeignKey to ContentType, but now I > can't use my test fixtures, since the IDs they point to are random > every time the test database is created. I can't dump the contenttypes > data because then I get many duplicate inserts, since Django rebuilds > them every time it sets up the test DB. Is there any way for me to use > both ContentType and unit tests?
The IDs won't be completely random, but they certainly will be fragile and subject to change. You have discovered ticket #7052; unfortunately, there isn't any easy fix at the moment. 1) Don't use fixtures - create your test objects in the setUp() method of your test using normal Python code. 2) Use the fixture to define the basic data in your objects, and then use the setUp() method to modify the contenttypes at runtime, based on the current values in the database. This means you don't serialize the contenttype objects themselves in your fixture, and you use and foreignkey reference to a contenttype as a temporary placeholder for the real value that will be inserted at runtime. Obviously, neither of these are ideal solutions. This bug is something I want to look at for Django v1.2. Yours Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---