Reputation: 3784
I have the following migration (logic removed for simplicity):
def migrate_existing_discounts(apps, _):
ModelA = apps.get_model('myapp', 'ModelA')
ModelB = apps.get_model('myapp', 'ModelB')
class Migration(migrations.Migration):
dependencies = [
('myapp', '0071_auto_20160531_1342'),
]
operations = [
migrations.RunPython(migrate_existing_discounts)
]
When running it the following exception rises:
LookupError: App 'myapp' doesn't have a 'modelb' model.
ModelA
inherits from models.Model
and it's successfully loaded. On the other hand, ModelB
inherits from TranslatableModel and so it breaks. I've read that (2 years ago) migrations used to have problems loading abstract classes(ticket#21786 and ticket#21519), and TranslatableModel is one of.
I've had this problem before and I ended up migrating with RunSQL instead, but I would like to know how to import the models properly, since there must be a way.
Note: The package django-hvad doesn't have migrations so there isn't any dependencies to add.
Upvotes: 9
Views: 1767
Reputation: 351
If all of your migrations are running from start to finish, the models you are referencing might not exist yet in your new database. Update your dependencies list inside the migration to reference the last migration file on the app where those models are defined.
Upvotes: 0