django_migration_testcase icon indicating copy to clipboard operation
django_migration_testcase copied to clipboard

What happens if we have a FK betweens apps?

Open plumdog opened this issue 9 years ago • 5 comments

I think this means that I didn't actually full fix #12

plumdog avatar Oct 26 '15 15:10 plumdog

Still not fixed for South. See skipped test: https://github.com/plumdog/django_migration_testcase/blob/003873a064d8571bd81059916f9b500a069afc1b/tests/test_second_app/tests.py#L77

plumdog avatar Oct 27 '15 11:10 plumdog

Is there any sort of workaround for this issue? Is it possible to force a model to accept a dummy foreign key?

djg321 avatar Jan 25 '16 19:01 djg321

@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 avatar Jan 25 '16 19:01 clokep

@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 avatar Jan 25 '16 20:01 djg321

@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

plumdog avatar Mar 02 '16 17:03 plumdog