Opened 10 years ago
Closed 9 years ago
#26114 closed Bug (fixed)
Removing Meta.db_table generates migration with wrong rename in comment (None)
| Reported by: | Daniel | Owned by: | PREMANAND |
|---|---|---|---|
| Component: | Migrations | Version: | 1.9 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
# myapp.models.py
#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;
Change History (7)
comment:1 by , 10 years ago
| Summary: | Removing Meta.db_table generates migration with wrong rename (None) → Removing Meta.db_table generates migration with wrong rename in comment (None) |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 9 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:3 by , 9 years ago
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,
)
)
We don't have the same problem in the initial creation of the table if the table name is "None". It defaults to the app name as normal.
comment:4 by , 9 years ago
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.
comment:6 by , 9 years ago
| Has patch: | set |
|---|
I think we don't have the needed information to put the actual name in the comment, but perhaps we could replace
Nonewith something like(default).