#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      |   Keywords:  migration
 Triage Stage:  Unreviewed  |  Has patch:  0
Easy pickings:  0           |      UI/UX:  0
----------------------------+-----------------------
 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')
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27168>
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/048.0a21506e90102510d847bed7e9891753%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to