﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27168	"""LookupError: App 'xxxxx' doesn't have a 'xxxxx' model"" with custom table name"	John	nobody	"Hi,

I recently wrote a migration script in order to migrate some date and one of the model uses a custom table name using db_table (let's call it ""myapp_my_custom_table"")

When I try to run the migration I got this error:
LookupError: App 'myapp' doesn't have a 'mymodel' model

After investigating, I found out that the model name MyModel (not the real one) is put in lower case then used as key to fetch the actual model class (
django.apps.config.AppConfig#get_model )

One of the item of the self.models is named after the db_table '''my_custom_table''', instead of the model name '''mymodel'''

The solution I found is to pass the table name instead of the model name.

Before:

{{{
def migrate_data(apps, schema_editor):
    mymodel_model = apps.get_model(
        app_label='myapp',
        model_name='MyModel')
}}}

After:

{{{
def migrate_data(apps, schema_editor):
    mymodel_model = apps.get_model(
        app_label='myapp',
        model_name='my_custom_table')
}}}

I don't know if it's the correct behaviour.

Please advise.
Thanks"	Bug	new	Migrations	1.8	Normal		migration		Unreviewed	0	0	0	0	0	0
