#23630: AlterModelTable doesn't rename auto-created tables
----------------------------+------------------------------------
     Reporter:  Naddiseo    |                    Owner:  nobody
         Type:  Bug         |                   Status:  new
    Component:  Migrations  |                  Version:  1.7
     Severity:  Normal      |               Resolution:
     Keywords:              |             Triage Stage:  Accepted
    Has patch:  0           |      Needs documentation:  0
  Needs tests:  0           |  Patch needs improvement:  0
Easy pickings:  0           |                    UI/UX:  0
----------------------------+------------------------------------
Changes (by Naddiseo):

 * status:  closed => new
 * resolution:  wontfix =>


Comment:

 Steps to reproduce:
 1. Create models as such:

 {{{#!python
 class Spam(models.Model):
         class Meta:
                 db_table = 'hello_spam'

 class Eggs(models.Model):
         class Meta:
                 db_table = 'hello_eggs'

         m2m = models.ManyToManyField(Spam)
 }}}

 2. Create, and run, a migration. Tables created:
 {{{
 $ sqlite3 db.sqlite3 .tables
 django_migrations  hello_eggs         hello_eggs_m2m     hello_spam
 }}}
 3. Remove the `Meta.db_table` entries.
 4. Create an empty migration.
 5. Add the following to the migration (this step should be automated, but
 is blocked on #23629):
 {{{#!python
 class Migration(migrations.Migration):

     dependencies = [
         ('spam', '0001_initial'),
     ]

     operations = [
         # Rename the models to what they should default to
         migrations.AlterModelTable(
                 name = 'Spam',
                 table = 'spam_spam'
         ),
         migrations.AlterModelTable(
                 name = 'Eggs',
                 table = 'spam_eggs'
         ),
     ]
 }}}
 6. Run migrations. Current tables:
 {{{
 $ sqlite3 db.sqlite3 .tables
 django_migrations  hello_eggs_m2m     spam_eggs          spam_spam
 }}}

 As you can see, the m2m table isn't renamed, and one would have to
 manually add the following to the migration:
 {{{#!python
 migrations.RunPython(lambda a, e: e.alter_db_table(None, 'hello_eggs_m2m',
 'spam_eggs_m2m'))
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23630#comment:4>
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/066.e5c3ac76bfa108b4c5eb885fecce5732%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to