#27168: "LookupError: App 'xxxxx' doesn't have a 'xxxxx' model" with custom
table
name
----------------------------+--------------------------------------
Reporter: chagh | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:
Keywords: migration | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by chagh):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
> 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')
> }}}
New description:
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
--
--
Ticket URL: <https://code.djangoproject.com/ticket/27168#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/063.369dbc7ef58d9b4add2cc3ecb54c9c6a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.