-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Models from app state aren't compatible (Cannot assign "<A: A object (1)>": "B.a_fk" must be a "A" instance) #292
Comments
I found a workaround: diff --git a/test_bad.py b/test_bad.py
index b6b5779..a385cde 100644
--- a/test_bad.py
+++ b/test_bad.py
@@ -1,5 +1,6 @@
def test_bad(migrator):
state = migrator.apply_initial_migration(('my_app', '0002_foo'))
+ state.clear_delayed_apps_cache()
A = state.apps.get_model('my_app', 'A')
B = state.apps.get_model('my_app', 'B') The |
Should we always call this function on our side? What do you think? 🤔 |
I guess so? 🤔 I think the |
Then, PR is welcome. Let's test it! |
hi 👋 Thanks for really well-prepared issue! It seems like we should call it, because it's also used in |
I'm running into a problem when I apply a migration with
Migrator.apply_initial_migration()
and then try to construct model instances using the returned app state. One model has a foreign key to another model, but the foreign key field does not accept an instance of that model (see below for the exact output and exception).I tried to reduce the setup as much a possible. In the end, two additional models and 2 indexes were necessary to trigger the issue. I tested it with django-test-migrations 1.2.0 and with Django 3.2.13 and 4.0.4. The attached ZIP archive contains a complete project which reproduces the issue:
app-state-bug.zip
To run the test, use the following couple of commands:
When running this, you should see the following output:
The text was updated successfully, but these errors were encountered: