#Old model
class MyModel(models.Model):
...
class Meta:
db_table = 'legacy_table'
#New model
class MyModel(models.Model):
...
# makemigrations output:
- Rename table for mymodel to None
# sqlmigrate output:
BEGIN;
--
-- Rename table for mymodel to None
--
RENAME TABLE `legacy_table` TO `myapp_mymodel`;
COMMIT;
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26114>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
* stage: Unreviewed => Accepted
Comment:
I think we
[https://github.com/django/django/blob/fb4272f0e6bbdaa3e19ed5fde59fdb5ab5a33baf/django/db/migrations/operations/models.py#L316-L317
don't have the needed information to put the actual name] in the comment,
but perhaps we could replace `None` with something like `(default)`.
--
Ticket URL: <https://code.djangoproject.com/ticket/26114#comment:1>
* owner: nobody => PREM1980
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/26114#comment:2>
Comment (by PREM1980):
I'm thinking the following, please review and provide your comments.
When someone provides "None" as the new table name, we won't detect that
as a change and just ignore it.
This is the new change that works.
if old_db_table_name != new_db_table_name and new_db_table_name != None:
self.add_operation(
app_label,
operations.AlterModelTable(
name=model_name,
table=new_db_table_name,
)
)
--
Ticket URL: <https://code.djangoproject.com/ticket/26114#comment:3>
Comment (by timgraham):
The change I proposed in comment 1 is about modifying
`AlterModelTable.describe()`. The autodetector shouldn't be changed like
that because then a migration changing the table name back to the default
wouldn't be created.
--
Ticket URL: <https://code.djangoproject.com/ticket/26114#comment:4>
Comment (by PREM1980):
The changes are made and here is the Github link.
https://github.com/PREM1980/django
Branch - ticket_26114
--
Ticket URL: <https://code.djangoproject.com/ticket/26114#comment:5>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/26114#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"5da7e3f7fd24381195e557d807118130ddbc5152" 5da7e3f]:
{{{
#!CommitTicketReference repository=""
revision="5da7e3f7fd24381195e557d807118130ddbc5152"
Fixed #26114 -- Fixed AlterModelTable.describe() if db_table is None.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26114#comment:7>