django_migration_testcase
django_migration_testcase copied to clipboard
What happens if we have a FK betweens apps?
I think this means that I didn't actually full fix #12
Still not fixed for South. See skipped test: https://github.com/plumdog/django_migration_testcase/blob/003873a064d8571bd81059916f9b500a069afc1b/tests/test_second_app/tests.py#L77
Is there any sort of workaround for this issue? Is it possible to force a model to accept a dummy foreign key?
@djg321 This should work OK with Django migrations (not South), I think. I've certainly done this with ForeignKey
fields to the auth.User
model. One thing I will note, however, is that you seem to have to force it to load the second-app. E.g. if I have a test in my custom_app
that ForeignKeys
to auth.User
, I'd do something like this:
class TestAddFoo(MigrationTest):
# Include an auth migration to make MigrationTest load that app's models.
before = [('custom_app', '0001_initial),
('auth', '0006_require_contenttypes_0002')]
after = [('custom_app', '0002_add_foo')]
Otherwise the following fails in the test:
def test_user(self):
User = self.get_model_before('auth.User')
@clokep Yeah, I haven't been able to get this to work with django 1.6 and South. Now, when trying to instantiate the main object, I am getting a ValueError
saying that the model that is the Foreign Key cannot be assigned because its not an instance of its own type.
@djg321 after an embarrassingly long time and trying too hard to find a crafty direct fix, I realised that there is a fairly sane workaround. Just use assign ids instead of models. See https://github.com/plumdog/django_migration_testcase/pull/24