Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
benwad opened this issue Jul 7, 2023 · 2 comments
Open

Comments

@benwad
Copy link

benwad commented Jul 7, 2023

Hi, I couldn't find anything about this issue so I thought I'd post it here. I have a test like this:

@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.

@skarzi
Copy link
Collaborator

skarzi commented Jul 11, 2023

Hi @benwad,

This kind of error usually happens when the migrations have invalid dependencies defined. Please double-check that the migration which populates your Video model is executed.

It will be really helpful if you can prepare the most straightforward code (models, tests, migrations, etc) that is still causing this issue, so we can debug it, and paste a full traceback, so we can have more context.

@benwad
Copy link
Author

benwad commented Jul 11, 2023

Thanks for the reply! I'll take a look at the migrations graph. manage.py migrate works fine, but we do have quite a big dependency graph and have done some squashes etc so there could be something strange in there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants