ITADN

"Relation {table} does not exist" when creating using prototype model

#376Openbenwad 创建于 2023-07-07
B
benwadcommented
Hi, I couldn't find anything about this issue so I thought I'd post it here. I have a test like this: ```python @pytest.mark.django_db def test_0104_migration(migrator_factory): migrator = migrator_factory("default") old_state = migrator.apply_initial_migration(("my_app", "0103_previous_migration")) Overlay = old_state.apps.get_model("my_app", "Overlay") OverlayVersion = old_state.apps.get_model("my_app", "OverlayVersion") Video = old_state.apps.get_model("my_other_app", "Video") video_1 = Video.objects.create() # This is where the error happens overlay_no_current_version = Overlay.objects.create(video=video_1,) ``` This gives me the error: `django.db.utils.ProgrammingError: relation "my_app_video" does not exist`. I also get the following error during teardown: `psycopg2.errors.UndefinedTable: relation "django_content_type" does not exist` The test is running inside docker, with Postgres as the DB backend. Is there something I'm missing with `apply_initial_migration` which might not be creating these tables? I also tried `Overlay.objects.create` and `OverlayVersion.objects.create` and I get the same error. How could I go about debugging this? The migration itself works, and I've rebuilt the whole container and run the whole migration graph a number of times.
2 条评论